应用程序中使用“forge"/>
如何在 React 应用程序中使用“forge
我正在尝试使用 forge-apis 包
const ForgeSDK = require('forge-apis');
但导入包并添加此行会导致在运行应用程序时弹出大约 40 个错误,从 开始
Module not found: Error: Can't resolve 'fs' in ...\node_modules\forge-apis\src
接下来是4期不同的... ode_modules\lru-memoizer\src\sync 丢失的文件
然后剩下的错误都是这样出来的:
ERROR in ./node_modules/forge-apis/src/api/ObjectsApi.js 40:16-31
Module not found: Error: Can't resolve 'path' in '...\node_modules\forge-apis\src\api'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
即使我安装了它声称丢失的软件包,这些错误仍然存在,知道我将如何解决这个问题吗?
如果问题在这里,这是我的 package.json:
{
"name": "onetwinvis",
"version": "0.1.0",
"private": true,
"dependencies": {
"@fortawesome/free-regular-svg-icons": "^6.4.0",
"@fortawesome/free-solid-svg-icons": "^6.4.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"assert": "^2.0.0",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"crypto": "^1.0.1",
"crypto-browserify": "^3.12.0",
"eslint-config-react-app": "^7.0.1",
"forge-apis": "^0.9.6",
"fs": "^0.0.1-security",
"https-browserify": "^1.0.0",
"node-polyfill-webpack-plugin": "^2.0.1",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"react": "^18.2.0",
"react-date-picker": "^10.0.3",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
"stream-browserify": "^3.0.0",
"url": "^0.11.0",
"util": "^0.12.5",
"web-vitals": "^2.1.4",
"webpack-cli": "^5.0.2"
},
"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"
]
}
}
回答如下:
forge-apis
包旨在使用 Node.js 在服务器端工作。
React 是一个构建客户端的库。你不应该将这个包与 React 一起使用。
不在客户端使用此包或不从客户端向 Autodesk API 发出直接请求的主要原因之一是保护您的应用程序的凭据安全。
但是,如果你真的想在客户端访问 API,你可以看看这个包:forge-server-utils。这是
forge-apis
的非官方替代方案,但有一个实验性客户端可以在浏览器上运行(身份验证除外)。
更多推荐
如何在 React 应用程序中使用“forge
发布评论