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' }
package.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"
}
}
答案 0 :(得分:1)
文档中似乎有错字,因为您可以检查node_modules
文件夹,并且应该看到babel-plugin-transform-redom-jsx
。因此,您的.rc
应该如下所示:
{
"plugins": [
"babel-plugin-transform-redom-jsx",
["@babel/plugin-transform-react-jsx", {
"pragma": "el"
}]
]
}