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.
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.
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"
]
}
Could someone suggest how to fix this / give some advice for using babel when publishing npm modules?
from Cannot find module 'babel-runtime/regenerator' Import locally vs Import from NPM
No comments:
Post a Comment