Webpack + Babel:./_assets/js/src/main.js模块中找不到错误

时间:2019-04-01 12:14:09

标签: javascript webpack babel

我通常在使用webpack时遇到问题。但是在这种情况下,控制台告诉我,Webpack无法找到core-js模块。在顶部警告中,它显示“我们建议通过corejs选项显式设置您正在使用的core-js版本”。但是如何指定core-js版本?在其他与webpack / babel相关的问题或官方文档中找不到任何提示。

控制台输出

 $ npm run build

    > jkk-onepager@1.0.0 build /Users/frankwenzel/Repositories/_GitLab/jkk-onepager
    > webpack


    WARNING: We noticed you're using the `useBuiltIns` option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via the `corejs` option.

    You should also be sure that the version you pass to the `corejs` option matches the version specified in your `package.json`'s `dependencies` section. If it doesn't, you need to run one of the following commands:

      npm install --save core-js@2    npm install --save core-js@3
      yarn add core-js@2              yarn add core-js@3

    @babel/preset-env: `DEBUG` option

    Using targets:
    {
      "android": "4",
      "chrome": "29",
      "edge": "15",
      "firefox": "52",
      "ie": "11",
      "ios": "7",
      "opera": "57",
      "safari": "9",
      "samsung": "4"
    }

    Using modules transform: auto

    Using plugins:
      transform-template-literals { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9" }
      transform-literals { "android":"4", "chrome":"29", "firefox":"52", "ie":"11", "ios":"7" }
      transform-function-name { "android":"4", "chrome":"29", "edge":"15", "firefox":"52", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-arrow-functions { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-block-scoped-functions { "android":"4", "chrome":"29", "ios":"7", "safari":"9" }
      transform-classes { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-object-super { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-shorthand-properties { "android":"4", "chrome":"29", "ie":"11", "ios":"7" }
      transform-duplicate-keys { "android":"4", "chrome":"29", "ie":"11", "ios":"7" }
      transform-computed-properties { "android":"4", "chrome":"29", "ie":"11", "ios":"7" }
      transform-for-of { "android":"4", "chrome":"29", "firefox":"52", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-sticky-regex { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-dotall-regex { "android":"4", "chrome":"29", "edge":"15", "firefox":"52", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-unicode-regex { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-spread { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-parameters { "android":"4", "chrome":"29", "edge":"15", "firefox":"52", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-destructuring { "android":"4", "chrome":"29", "edge":"15", "firefox":"52", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-block-scoping { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-typeof-symbol { "android":"4", "chrome":"29", "ie":"11", "ios":"7" }
      transform-new-target { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-regenerator { "android":"4", "chrome":"29", "firefox":"52", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-exponentiation-operator { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-async-to-generator { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      proposal-async-generator-functions { "android":"4", "chrome":"29", "edge":"15", "firefox":"52", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      proposal-object-rest-spread { "android":"4", "chrome":"29", "edge":"15", "firefox":"52", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      proposal-unicode-property-regex { "android":"4", "chrome":"29", "edge":"15", "firefox":"52", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      proposal-json-strings { "android":"4", "chrome":"29", "edge":"15", "firefox":"52", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      proposal-optional-catch-binding { "android":"4", "chrome":"29", "edge":"15", "firefox":"52", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      transform-named-capturing-groups-regex { "android":"4", "chrome":"29", "edge":"15", "firefox":"52", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }

    Using polyfills with `entry` option:

    [/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src/main.js] Replaced @babel/polyfill entries with the following polyfills:
      es6.array.copy-within { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "samsung":"4" }
      es6.array.fill { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "samsung":"4" }
      es6.array.find { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "samsung":"4" }
      es6.array.find-index { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "samsung":"4" }
      es7.array.flat-map { "android":"4", "chrome":"29", "edge":"15", "firefox":"52", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      es6.array.from { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      es7.array.includes { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      es6.array.iterator { "android":"4", "chrome":"29", "ie":"11", "ios":"7" }
      es6.array.of { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "samsung":"4" }
      es6.array.sort { "android":"4", "chrome":"29", "ios":"7", "safari":"9", "samsung":"4" }
      es6.array.species { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      es6.date.to-json { "ios":"7", "safari":"9" }
      es6.date.to-primitive { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      es6.function.has-instance { "android":"4", "chrome":"29", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }
      es6.function.name { "ie":"11" }
      es6.map { "android":"4", "chrome":"29", "firefox":"52", "ie":"11", "ios":"7", "safari":"9", "samsung":"4" }

    Hash: 6c65e92d03f5b74daa97
    Version: webpack 4.29.6
    Time: 2613ms
    Built at: 2019-04-01 14:03:40
        Asset     Size  Chunks             Chunk Names
    bundle.js  118 KiB     app  [emitted]  app
    Entrypoint app = bundle.js
    [./_assets/js/src/main.js] 24.3 KiB {app} [built]
        + 48 hidden modules

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.array.copy-within' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 1:0-47

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.array.fill' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 2:0-40

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.array.find' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 3:0-40

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.array.find-index' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 4:0-46

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.array.from' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 6:0-40

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.array.iterator' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 8:0-44

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.array.of' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 9:0-38

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.array.sort' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 10:0-40

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.array.species' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 11:0-43

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.date.to-json' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 12:0-42

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.date.to-primitive' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 13:0-47

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.function.has-instance' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 14:0-51

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.function.name' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 15:0-43

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.map' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 16:0-33

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.math.acosh' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 17:0-40

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.math.asinh' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 18:0-40

    ERROR in ./_assets/js/src/main.js
    Module not found: Error: Can't resolve 'core-js/modules/es6.math.atanh' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
     @ ./_assets/js/src/main.js 19:0-40


     @ ./_assets/js/src/main.js 129:0-42
    npm ERR! code ELIFECYCLE
    npm ERR! errno 2
    npm ERR! jkk-onepager@1.0.0 build: `webpack`
    npm ERR! Exit status 2
    npm ERR! 
    npm ERR! Failed at the jkk-onepager@1.0.0 build script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in:

package.json

{
  "name": "jkk-onepager",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack",
    "start": "webpack-dev-server"
  },
  "repository": {
    "type": "git",
    "url": "http://10.8.1.1:850/root/jkk-onepager.git"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/core": "^7.4.0",
    "@babel/polyfill": "^7.4.0",
    "@babel/preset-env": "^7.4.2",
    "babel-loader": "^8.0.5",
    "babel-plugin-syntax-flow": "^6.18.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-decorators-legacy": "^1.3.5",
    "babel-plugin-transform-flow-strip-types": "^6.22.0",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-polyfill": "^6.26.0",
    "babel-preset-es2015": "^6.24.1",
    "core-js": "^3.0.0",
    "webpack-dev-server": "^3.2.1"
  },
  "devDependencies": {
    "babel-core": "^7.0.0-bridge.0",
    "babel-preset-env": "^1.7.0",
    "webpack": "^4.29.6",
    "webpack-cli": "^3.3.0"
  }
}

.babelrc

{
    "presets": [
        ["@babel/preset-env", {
            "useBuiltIns": "entry",
            "debug": true
        }]
    ]
}

编辑:

经过一些额外的研究,我找到了并尝试过:

webpack --progress --color --watch --display-error-details

ERROR in ./_assets/js/src/main.js
Module not found: Error: Can't resolve 'core-js/modules/web.dom.iterable' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
resolve 'core-js/modules/web.dom.iterable' in '/Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src'
  Parsed request is a module
  using description file: /Users/frankwenzel/Repositories/_GitLab/jkk-onepager/package.json (relative path: ./_assets/js/src)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      /Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/src/node_modules doesn't exist or is not a directory
      /Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/js/node_modules doesn't exist or is not a directory
      /Users/frankwenzel/Repositories/_GitLab/jkk-onepager/_assets/node_modules doesn't exist or is not a directory
      /Users/frankwenzel/Repositories/_GitLab/node_modules doesn't exist or is not a directory
      /Users/frankwenzel/Repositories/node_modules doesn't exist or is not a directory
      /Users/frankwenzel/node_modules doesn't exist or is not a directory
      /Users/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /Users/frankwenzel/Repositories/_GitLab/jkk-onepager/node_modules
        using description file: /Users/frankwenzel/Repositories/_GitLab/jkk-onepager/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /Users/frankwenzel/Repositories/_GitLab/jkk-onepager/node_modules/core-js/package.json (relative path: ./modules/web.dom.iterable)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /Users/frankwenzel/Repositories/_GitLab/jkk-onepager/node_modules/core-js/modules/web.dom.iterable doesn't exist
            .wasm
              Field 'browser' doesn't contain a valid alias configuration
              /Users/frankwenzel/Repositories/_GitLab/jkk-onepager/node_modules/core-js/modules/web.dom.iterable.wasm doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /Users/frankwenzel/Repositories/_GitLab/jkk-onepager/node_modules/core-js/modules/web.dom.iterable.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /Users/frankwenzel/Repositories/_GitLab/jkk-onepager/node_modules/core-js/modules/web.dom.iterable.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              /Users/frankwenzel/Repositories/_GitLab/jkk-onepager/node_modules/core-js/modules/web.dom.iterable.json doesn't exist
            as directory
              /Users/frankwenzel/Repositories/_GitLab/jkk-onepager/node_modules/core-js/modules/web.dom.iterable doesn't exist

0 个答案:

没有答案