1

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"
   }
}
4

1 回答 1

1

看起来文档中有错字,因为您可以检查您的node_modules文件夹,您应该会看到babel-plugin-transform-redom-jsx. 所以你.rc应该看起来像:

{
  "plugins": [
    "babel-plugin-transform-redom-jsx",
    ["@babel/plugin-transform-react-jsx", {
      "pragma": "el"
    }]
  ]
}
于 2019-01-22T04:11:08.067 回答