此安装导致模块找不到,即使它在我的节点模块目录和package.json文件中可用
import * as Office from '@microsoft/office-js
这是我的package.json文件
{
"name": "kazy",
"version": "0.1.0",
"private": true,
"dependencies": {
"@microsoft/office-js": "^1.1.84",
"@microsoft/office-js-helpers": "^1.0.2",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"docx-to-pdf": "^1.1.0",
"docx-to-pdf-converter": "0.0.6",
"docxtemplater": "^3.34.3",
"google-fonts": "^1.0.0",
"jszip": "^3.10.1",
"pizzip": "^3.1.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-loader-spinner": "^5.3.4",
"react-pdf": "^6.2.2",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"copy-webpack-plugin": "^11.0.0",
"webpack": "^5.76.1",
"webpack-cli": "^5.0.1"
}
}
我试着为我的react web应用程序安装office-js,它安装得很好,但试图导入它不起作用,它导致模块未找到错误,不像office-js-helper那样工作
1条答案
按热度按时间ffdz8vbo1#
@microsoft/office-js
不能像普通NPM包那样导入:在本地安装NPM包会在运行npm install命令的目录的node_modules@microsoft\office-js\dist文件夹中创建一组静态Office.js文件。要使用NPM包,请执行以下操作:
1.手动或作为构建脚本的一部分(例如,如果您使用Webpack,则使用CopyWebpackPlugin),从您选择的目的地(例如,从您的Web服务器的/assets/office-js/目录)提供文件
1.在外接程序项目的HTML文件内的标记中引用该位置。
例如,如果将dist文件夹的内容添加到项目的assets/office-js目录中,则需要将以下标记添加到HTML文件中:
Source
此外,使用NPM包也有缺点,因为它已经过时了。所以,你应该使用我提供的源代码中包含的CDN版本。