我正在使用webpack5,无法导入.json文件。据我所知,我不需要安装加载程序来导入json。尽管如此,我还是安装了“json5加载程序”,并设置了以下规则:
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";这段代码使用的是“创建-反应-应用程序”,而不是webpack5。
为了重现这个问题,我创建了一个simle json:
Name.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 |发布于 2022-03-14 18:58:40
您可能依赖热重新加载加载您的webpack配置更改,但这是不正确的,您需要停止并重新启动webpack服务器,以确保这些更改生效。
https://stackoverflow.com/questions/68964789
复制相似问题