gpt4 book ai didi

javascript - 使用用 ES6 编写的 npm 模块和 react-scripts

转载 作者:行者123 更新时间:2023-11-29 15:14:34 30 4
gpt4 key购买 nike

在我的项目中,我需要使用 npm 模块 ipfs-api使用 create-react-app

我可以运行 npm start 并运行项目。

但是当我尝试使用 react-scripts build 构建项目时,它会抛出以下错误

Failed to compile.

Failed to minify the code from this file:

./node_modules/ipfs-api/src/utils/module-config.js:7

Read more here: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify

根据错误日志中提供的链接中的建议,我尝试使用,

"dependencies": {
...
"ipfs-api": "github:atfornes/js-ipfs-api#transpiled",
...
}

而不是 "ipfs-api": "^22.0.0",。虽然这解决了 ipfs-api 的错误,但其他依赖模块(可能与 ipfsapi 一起安装)不断给出相同类型的 Failed to minify 错误,我停止手动转译它们。

在使用命令 react-scripts build 之前,有没有办法将所有依赖节点模块转换为 es5?或者有什么其他方法可以解决这个问题?

最佳答案

通常,客户端或平台独立包在发布时被编译为 ES5。您遇到此问题可能表明该软件包不适用于客户端。

作为the documentation解释说,该包包含一个用于浏览器的包,其中包含在客户端运行它所需的 polyfilled Node 功能(流等)。

它应该用作全局:

import 'ipfs-api/dist';

ipfs(...)

Is there a way to transile all the dependent node modules to es5 while before using the command react-scripts build ?

这将需要弹出 create-react-app 配置并配置 Webpack 以正确转译此包。 This example文档中的内容展示了如何将特定于节点的部分配置为为浏览器捆绑。

关于javascript - 使用用 ES6 编写的 npm 模块和 react-scripts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50541034/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com