![](/img/trans.png)
[英]Migration from webpack4 -> webpack5, bundled file will have a faulty url when it gets requested?
[英]webpack5 does not import content from .json file?
我正在使用 webpack5,无法导入 .json 文件。 据我所知,我不需要安装 loader 来导入 json。N.netheless,我确实安装了“json5-loader”并设置了这个规则:
rules: [
{
test: /\.json5$/i,
loader: 'json5-loader',
type: 'javascript/auto',
// this option did not help neither
options: {
esModule: true,
},
},
],
无论哪种方式,建筑都会给我这个错误。
SyntaxError: /home/Documents/projects/ethereum/src/contracts/Tether.json: Missing semicolon. (2:16)
1 | {
> 2 | "contractName": "Tether",
| ^
3 | "abi": [
4 | {
5 | "inputs": [],
显然,它不识别JSON个文件。
import Tether from "./contracts/Tether.json";
此代码适用于“create-react-app”但不适用于 webpack5
为了重现这个问题,我创建了一个简单的 json:
名称.json:
{ "name": "yilmaz" }
并尝试将其导入同一目录:
import Name from "./contracts/Name.json";
// import Tether from "./contracts/Tether.json";
收到此错误:
SyntaxError: /home/Documents/projects/ethereum/clarion-ethereum/src/contracts/Name.json: Missing semicolon. (1:8)
> 1 | { "name": "yilmaz" }
| ^
2 |
您可能依赖热重载来加载您的 webpack 配置更改,但这是不正确的,您需要停止并重新启动 webpack 服务器才能看到这些更改生效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.