简体   繁体   English

webpack 和 babel-polyfill:无法解析源目录中的“core-js/modules/es6.array.map”

[英]webpack & babel-polyfill: Can't resolve 'core-js/modules/es6.array.map' in source directory

I'm facing this error when I execute webpack :我在执行webpackwebpack这个错误:

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 : index.ts

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

.babelrc : .babelrc :

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

webpack.config.js : 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/ .我认为错误试图解析src/的模块而不是node_modules/非常奇怪。

I tried removing node_modules and package.json and then npm i , but it didn't change the situation.我尝试删除node_modulespackage.json ,然后删除npm i ,但它没有改变情况。

I also tried another way to use @babel/polyfill described here .我还尝试了另一种使用此处描述的@babel/polyfill

Setting useBuiltIns to 'entry' just increased the number of similar errors.useBuiltIns设置为'entry'只会增加类似错误的数量。 Setting it to false caused different errors.将其设置为false导致不同的错误。

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/ .似乎core-jsregenerator-runtime应该安装在node_modules/@babel/polyfill/ Currently, there are only index.js and noConflict.js in the directory.目前,目录中只有index.jsnoConflict.js Do I have to manually install those modules in this directory?我是否必须在此目录中手动安装这些模块?

Try to add the following in your resolve s -尝试在您的resolve添加以下内容 -

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 React 应用程序中从 babel-polyfill 切换到 core-js - Switching from babel-polyfill to core-js in React app core-js / babel-polyfill polyfilled函数显示为[本机代码] - core-js/babel-polyfill polyfilled functions appear as [native code] 找不到模块:错误:无法解析“core-js/modules/es.error.cause.js” - Module not found: Error: Can't resolve 'core-js/modules/es.error.cause.js' 如何解决找不到模块:无法在 Material-UI 中解析“@babel/runtime/core-js/map” - How to solve Module not found: Can't resolve '@babel/runtime/core-js/map' in Material-UI require('core-js / es6 / map')polyfill不适用于IE11上的扩展Map对象 - require('core-js/es6/map') polyfill not working for spread Map object on IE11 我可以导入babel-polyfill模块而不是全部吗? - Can I import babel-polyfill modules rather than all in? 如果我使用babel-polyfill,我可以使用Typescript定位ES6吗? - Can I target ES6 with Typescript if I am using babel-polyfill? babel-polyfill的性质 - Properties of babel-polyfill babel + core-js + webpack 使代码支持旧版 chrome,许多 node_modules 文件引发“export ... was not found”错误 - babel + core-js + webpack make code support old chrome, many node_modules file raise "export ... was not found" error 找不到此依赖项:* core-js/modules/es6.regexp.split - This dependency was not found: * core-js/modules/es6.regexp.split
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM