admin管理员组

文章数量:1317906

I'm facing this error when I execute webpack:

Module not found: Error: Can't resolve 'core-js/modules/es6.array.map' in '/path/to/project/src'
 @ ./src/index.ts 1:0-39

index.ts:

console.log([1, 2, 3].map(x => x * x));

.babelrc:

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "useBuiltIns": "usage"
      }
    ]
  ]
}

webpack.config.js:

const path = require('path');

module.exports = {
  mode: 'development',

  entry: './src/index.ts',
  devtool: false,
  output: {
    filename: 'bundle.js',
    path: path.join(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: [
          { loader: 'babel-loader' },
          { loader: 'ts-loader' }
        ]
      }
    ]
  },
  resolve: {
    extensions: [
      '.ts'
    ]
  }
};

I think it's very weird that the error is trying to resolve the module in src/, not node_modules/.

I tried removing node_modules and package.json and then npm i, but it didn't change the situation.

I also tried another way to use @babel/polyfill described here.

Setting useBuiltIns to 'entry' just increased the number of similar errors. Setting it to false caused different errors.

Module not found: Error: Can't resolve 'core-js/es6' in '/path/to/project/node_modules/@babel/polyfill/lib'
 @ ./node_modules/@babel/polyfill/lib/index.js 3:0-22
 @ multi @babel/polyfill ./src/index.ts

ERROR in ./node_modules/@babel/polyfill/lib/index.js
Module not found: Error: Can't resolve 'regenerator-runtime/runtime' in '/path/to/project/node_modules/@babel/polyfill/lib'
 @ ./node_modules/@babel/polyfill/lib/index.js 23:0-38
 @ multi @babel/polyfill ./src/index.ts

It seems core-js and regenerator-runtime should be installed in node_modules/@babel/polyfill/. Currently, there are only index.js and noConflict.js in the directory. Do I have to manually install those modules in this directory?

I'm facing this error when I execute webpack:

Module not found: Error: Can't resolve 'core-js/modules/es6.array.map' in '/path/to/project/src'
 @ ./src/index.ts 1:0-39

index.ts:

console.log([1, 2, 3].map(x => x * x));

.babelrc:

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "useBuiltIns": "usage"
      }
    ]
  ]
}

webpack.config.js:

const path = require('path');

module.exports = {
  mode: 'development',

  entry: './src/index.ts',
  devtool: false,
  output: {
    filename: 'bundle.js',
    path: path.join(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: [
          { loader: 'babel-loader' },
          { loader: 'ts-loader' }
        ]
      }
    ]
  },
  resolve: {
    extensions: [
      '.ts'
    ]
  }
};

I think it's very weird that the error is trying to resolve the module in src/, not node_modules/.

I tried removing node_modules and package.json and then npm i, but it didn't change the situation.

I also tried another way to use @babel/polyfill described here.

Setting useBuiltIns to 'entry' just increased the number of similar errors. Setting it to false caused different errors.

Module not found: Error: Can't resolve 'core-js/es6' in '/path/to/project/node_modules/@babel/polyfill/lib'
 @ ./node_modules/@babel/polyfill/lib/index.js 3:0-22
 @ multi @babel/polyfill ./src/index.ts

ERROR in ./node_modules/@babel/polyfill/lib/index.js
Module not found: Error: Can't resolve 'regenerator-runtime/runtime' in '/path/to/project/node_modules/@babel/polyfill/lib'
 @ ./node_modules/@babel/polyfill/lib/index.js 23:0-38
 @ multi @babel/polyfill ./src/index.ts

It seems core-js and regenerator-runtime should be installed in node_modules/@babel/polyfill/. Currently, there are only index.js and noConflict.js in the directory. Do I have to manually install those modules in this directory?

Share Improve this question edited Feb 25, 2019 at 15:57 legogo asked Feb 25, 2019 at 15:10 legogolegogo 1,2371 gold badge10 silver badges11 bronze badges 4
  • Have you included @babel/polyfill ? – Alex G Commented Feb 25, 2019 at 15:15
  • 1 No, because when useBuiltIns is 'usage' @babel/polyfill should not be included in source (babeljs.io/docs/en/babel-polyfill) – legogo Commented Feb 25, 2019 at 15:35
  • Why are you using ts-loader? babel has built in support for TS as of v7. Did you try installing core-js the docs say you may need to - babeljs.io/docs/en/babel-preset-env#usebuiltins? – nanobar Commented Feb 25, 2019 at 16:09
  • I symbolic-linked node_module/core-js to node_modules/@babel/polyfill/lib/core-js and src/core-js and it seems accessible, but the errors still occur. – legogo Commented Feb 25, 2019 at 16:39
Add a ment  | 

1 Answer 1

Reset to default 2

Try to add the following in your resolves -

  resolve: {
    extensions: [
      '.ts',
      '.js' // add this
    ]
  }

本文标签: