找不到模块"babel-runtime/regenerator"本地导入与从NPM导入 [英] Cannot find module 'babel-runtime/regenerator' Import locally vs Import from NPM
问题描述
我正在使用NPM模块,而babel配置却遇到了问题.我正在使用ES6,特别是用于异步/等待,静态类方法和导入/导出.
I'm working on an NPM module and I've been having issues with my babel configuration. I am using ES6, specifically with async / await, static class methods and import / export.
起初,我遇到了以下常见问题: ReferenceError:未定义regeneratorRuntime
.因此,我将 babel-plugin-transform-runtime
安装为dev依赖项,并将其添加到 .babelrc
中的插件中.当需要使用路径名或通过npm作为依赖项的模块时,我遇到错误 Error:找不到模块'babel-runtime/regenerator'
.看来要解决此问题,我必须要求 babel-runtime
,但是,很多人似乎建议您在发布模块时不要这样做.
At first, I got the common issue of: ReferenceError: regeneratorRuntime is not defined
. I, therefore, installed babel-plugin-transform-runtime
as a dev dependency and added it to the plugins in .babelrc
. When requiring the module with either the path name or through npm as a dependency I ran into the error Error: Cannot find module 'babel-runtime/regenerator'
. It seems that to resolve this I'd have to require babel-runtime
, however, a lot of people seem to recommend not doing this when it's a module that you are publishing.
在查找了一些指南之后,我发现一个建议不要使用导入/导出的指南,因此我尝试了该指南.在构建并在本地要求它后,它就可以工作了.但是,当发布到npm并作为依赖项导入时,我继续遇到错误:错误:找不到模块"babel-runtime/regenerator"
.
After looking for some guides, I found one that suggested not using import / export, so I tried that. After building and requiring it locally it worked. However, when publishing to npm and importing as a dependency I continue to get the error: Error: Cannot find module 'babel-runtime/regenerator'
.
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^10.0.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"eslint": "^5.12.0",
"eslint-config-prettier": "^3.4.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"husky": "^1.3.1",
"jest": "^23.6.0",
"lint-staged": "^8.1.0",
"nodemon": "^1.18.9",
"prettier": "^1.15.3",
"rimraf": "^2.6.3"
},
{
"presets": [
"env"
],
plugins: [
"babel-plugin-transform-runtime"
]
}
有人可以在发布npm模块时建议如何解决此问题/为使用babel提供一些建议吗?
Could someone suggest how to fix this / give some advice for using babel when publishing npm modules?
推荐答案
根据文档,您需要两个模块:
According to the docs you need two modules:
-
转换插件
babel-plugin-transform-runtime
(您可以已有)
以及实际填充或填充的实际运行时模块否则在运行时(即在浏览器中)启用功能为 babel-runtime
and the actual runtime module which polyfills or
otherwise enables the features at runtime (i.e. in the browser) is babel-runtime
您可以像
"babel-runtime": "^6.26.0"
或只是
npm i babel-runtime --save
其他人似乎对通天塔6也有同样的问题:
Other people seem to have the same problem with babel 6:
https://github.com/nozzle/react-static/issues/685
这篇关于找不到模块"babel-runtime/regenerator"本地导入与从NPM导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!