如何修复“无法解析 npm 链接模块中的‘@babel/runtime/regenerator’”?

Mis*_*cot 6 javascript npm webpack babeljs

使用 webpack+babel 转译我的一些链接(如在 npm 链接中)依赖项时出现该错误。

我正在使用最新版本的 npm/webpack/babel。我的核心依赖项用 JS6 编写并作为 NPM 包发布。我只捆绑了我的 webapps 和更高级别的包,并且我配置 webpack 在这样做时转换核心 deps。

换句话说,我的一些依赖项node_modules需要转译。当我使用已发布的包(npm install)时,它工作正常,但是当我使用开发存储库(npm 链接)时,它因该错误而失败:

错误:无法在{模块存储库路径,不在项目树下}中解析“@babel/runtime/regenerator”

我发现的临时修复是npm install --no-save @babel/runtime在核心依赖项存储库中,但是每次我都会删除npm update它,所以很烦人。

webpack.config.js:

const webpack = require('webpack')

const config = {
  devtool: 'source-map',
  module: {
    rules: [
     {
        test: /\.(js)$/,
        loader: 'babel-loader'
     }
    ]
  }
}

const library = Object.assign({}, config, {
  entry: './src/index.js',
  output: {
    path: __dirname + '/web',
    filename: 'cosmic-lib.js',
    library: 'cosmicLib',
    libraryTarget: 'umd',
    globalObject: 'typeof self !== \'undefined\' ? self : this'
  },
  externals: { 'stellar-sdk': 'stellar-sdk' }
})

module.exports = [ library ]
Run Code Online (Sandbox Code Playgroud)

我想找到一种方法来在开发环境中转换这些核心依赖项,而无需更改它们的原始存储库。