gpt4 book ai didi

javascript - 带有 .babelrc 的 Babel 如何修复 MODULE_NOT_FOUND?

转载 作者:行者123 更新时间:2023-11-30 19:52:56 26 4
gpt4 key购买 nike

Babel 告诉我一个插件不存在,但它确实存在。 (我可以用 babel-cli 编译得很好,但是它不支持设置 pragma 选项。所以我只能使用恶心的 .babelrc 文件)我在这里做错了什么?

.babelrc

{
"plugins": [
"babel-plugin-redom-jsx",
["@babel/plugin-transform-react-jsx", {
"pragma": "el"
}]
]
}

npx babel frontend.js

{ Error: Cannot find module 'babel-plugin-redom-jsx' from '/home/user/Documents/my_program'
at Function.module.exports [as sync] (/home/user/Documents/my_program/node_modules/resolve/lib/sync.js:58:15)
at resolveStandardizedName (/home/user/Documents/my_program/node_modules/@babel/core/lib/config/files/plugins.js:101:31)
at resolvePlugin (/home/user/Documents/my_program/node_modules/@babel/core/lib/config/files/plugins.js:54:10)
at loadPlugin (/home/user/Documents/my_program/node_modules/@babel/core/lib/config/files/plugins.js:62:20)
at createDescriptor (/home/user/Documents/my_program/node_modules/@babel/core/lib/config/config-descriptors.js:154:9)
at items.map (/home/user/Documents/my_program/node_modules/@babel/core/lib/config/config-descriptors.js:109:50)
at Array.map (<anonymous>)
at createDescriptors (/home/user/Documents/my_program/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
at createPluginDescriptors (/home/user/Documents/my_program/node_modules/@babel/core/lib/config/config-descriptors.js:105:10)
at plugins (/home/user/Documents/my_program/node_modules/@babel/core/lib/config/config-descriptors.js:40:19) code: 'MODULE_NOT_FOUND' }

包.json :

{
"devDependencies":
{
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@babel/preset-env": "^7.3.0",
"babel-plugin-transform-redom-jsx": "^2.0.0",
"babel-preset-minify": "^0.5.0",
"babelify": "^10.0.0",
"browserify": "^16.2.3",
"redom": "^3.18.0",
"terser": "^3.14.1"
}
}

最佳答案

文档中似乎有错别字,因为您可以检查 node_modules 文件夹,您应该会看到 babel-plugin-transform-redom-jsx。所以你的 .rc 应该是这样的:

{
"plugins": [
"babel-plugin-transform-redom-jsx",
["@babel/plugin-transform-react-jsx", {
"pragma": "el"
}]
]
}

关于javascript - 带有 .babelrc 的 Babel 如何修复 MODULE_NOT_FOUND?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54301008/

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