【问题标题】:Module build failed, Laravel 6 project模块构建失败,Laravel 6 项目
【发布时间】:2020-04-29 12:57:08
【问题描述】:

我在 laravel 6 中创建了新项目,安装 npm 后运行 npm run watch,我收到此错误。

Ahmed@DESKTOP-G216VK0 MINGW64 /c/laragon/www/larabiz
$ npm run watch

> @ watch C:\laragon\www\larabiz
> npm run development -- --watch


> @ development C:\laragon\www\larabiz
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js "--watch"        

10% building 1/1 modules 0 active
webpack is watching the files…

98% after emitting SizeLimitsPlugin

 ERROR  Failed to compile with 1 errors                                                                                                                         9:37:44 PM
 error  in ./resources/js/app.js

Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Package exports for 'C:\laragon\www\larabiz\node_modules\@babel\helper-compilation-targets' do not define a '.' subpath
    at applyExports (internal/modules/cjs/loader.js:485:15)
    at resolveExports (internal/modules/cjs/loader.js:508:12)
    at Function.Module._findPath (internal/modules/cjs/loader.js:577:20)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:879:27)
    at Function.Module._load (internal/modules/cjs/loader.js:785:27)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at require (C:\laragon\www\larabiz\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
    at Object.<anonymous> (C:\laragon\www\larabiz\node_modules\@babel\preset-env\lib\debug.js:8:33)
    at Module._compile (C:\laragon\www\larabiz\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
    at Module.load (internal/modules/cjs/loader.js:914:32)
    at Function.Module._load (internal/modules/cjs/loader.js:822:14)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at require (C:\laragon\www\larabiz\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
    at Object.<anonymous> (C:\laragon\www\larabiz\node_modules\@babel\preset-env\lib\index.js:11:14)
    at Module._compile (C:\laragon\www\larabiz\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
    at Module.load (internal/modules/cjs/loader.js:914:32)
    at Function.Module._load (internal/modules/cjs/loader.js:822:14)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at require (C:\laragon\www\larabiz\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
    at requireModule (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\files\plugins.js:165:12)
    at loadPreset (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\files\plugins.js:83:17)
    at createDescriptor (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-descriptors.js:154:9)
    at C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-descriptors.js:109:50
    at Array.map (<anonymous>)
    at createDescriptors (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-descriptors.js:109:29)
    at createPresetDescriptors (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-descriptors.js:101:10)      
    at C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-descriptors.js:58:104
    at cachedFunction (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\caching.js:62:27)
    at cachedFunction.next (<anonymous>)
    at evaluateSync (C:\laragon\www\larabiz\node_modules\gensync\index.js:244:28)
    at sync (C:\laragon\www\larabiz\node_modules\gensync\index.js:84:14)
    at presets (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-descriptors.js:29:84)
    at mergeChainOpts (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-chain.js:320:26)
    at C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-chain.js:283:7

 @ multi ./resources/js/app.js ./resources/sass/app.scss

       Asset      Size   Chunks             Chunk Names
/css/app.css   0 bytes  /js/app  [emitted]  /js/app
  /js/app.js  7.86 KiB  /js/app  [emitted]  /js/app

ERROR in ./resources/js/app.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Package exports for 'C:\laragon\www\larabiz\node_modules\@babel\helper-compilation-targets' do not define a '.' subpath
    at applyExports (internal/modules/cjs/loader.js:485:15)
    at resolveExports (internal/modules/cjs/loader.js:508:12)
    at Function.Module._findPath (internal/modules/cjs/loader.js:577:20)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:879:27)
    at Function.Module._load (internal/modules/cjs/loader.js:785:27)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at require (C:\laragon\www\larabiz\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
    at Object.<anonymous> (C:\laragon\www\larabiz\node_modules\@babel\preset-env\lib\debug.js:8:33)
    at Module._compile (C:\laragon\www\larabiz\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
    at Module.load (internal/modules/cjs/loader.js:914:32)
    at Function.Module._load (internal/modules/cjs/loader.js:822:14)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at require (C:\laragon\www\larabiz\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
    at Object.<anonymous> (C:\laragon\www\larabiz\node_modules\@babel\preset-env\lib\index.js:11:14)
    at Module._compile (C:\laragon\www\larabiz\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
    at Module.load (internal/modules/cjs/loader.js:914:32)
    at Function.Module._load (internal/modules/cjs/loader.js:822:14)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at require (C:\laragon\www\larabiz\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
    at requireModule (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\files\plugins.js:165:12)
    at loadPreset (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\files\plugins.js:83:17)
    at createDescriptor (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-descriptors.js:154:9)
    at C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-descriptors.js:109:50
    at Array.map (<anonymous>)
    at createDescriptors (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-descriptors.js:109:29)
    at createPresetDescriptors (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-descriptors.js:101:10)
    at C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-descriptors.js:58:104
    at cachedFunction (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\caching.js:62:27)
    at cachedFunction.next (<anonymous>)
    at evaluateSync (C:\laragon\www\larabiz\node_modules\gensync\index.js:244:28)
    at sync (C:\laragon\www\larabiz\node_modules\gensync\index.js:84:14)
    at presets (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-descriptors.js:29:84)
    at mergeChainOpts (C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-chain.js:320:26)
    at C:\laragon\www\larabiz\node_modules\@babel\core\lib\config\config-chain.js:283:7
 @ multi ./resources/js/app.js ./resources/sass/app.scss /js/app[0]

Package.json文件:

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {

        "babel-core": "^6.26.0",
        "babel-loader": "^7.1.4",
        "babel-preset-env": "^1.6.1",
        "axios": "^0.19",
        "cross-env": "^5.1",
        "laravel-mix": "^4.0.7",
        "lodash": "^4.17.13",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.15.2",
        "sass-loader": "^7.1.0",
        "vue-template-compiler": "^2.6.11",
        "webpack": "^4.41.5"
    }
}

【问题讨论】:

  • 嗨,我在尝试安装全新的 Laravel 6 后遇到了完全相同的错误。
  • 降级 bable 版本 - ``` "babel-core": "^6.26.0" ```
  • fwiw,我在一个 nativescript 项目中,遇到了同样的错误。看起来和 babel 有关系。

标签: laravel npm


【解决方案1】:

对于 Windows 用户,如果你使用巧克力,只需在终端中运行它,重新打开你尝试运行 dev 的终端,一切都会很好:

choco upgrade nodejs

【讨论】:

    【解决方案2】:

    请注意,我首先升级到nodejs 13.6.0,然后执行以下步骤解决了这个问题:

    vagrant@ubuntu-bionic:~$ rm -rf node_modules
    vagrant@ubuntu-bionic:~$ rm package-lock.json yarn.lock
    vagrant@ubuntu-bionic:~$ npm cache clear --force
    vagrant@ubuntu-bionic:~$ npm install cross-env
    vagrant@ubuntu-bionic:~$ npm install 
    vagrant@ubuntu-bionic:~$ npm run dev
    

    请注意,我需要跨环境,因为我正在使用 Windows 10 主机和 Ubuntu Vagrant VM 进行开发。

    更多详情请查看@JLHwungError: Package exports for <path to project folder>/node_modules/@babel/helper-compilation-targets' do not define a '.' subpath的回复

    【讨论】:

      【解决方案3】:

      干杯,我今天遇到了这个问题。

      edit: Before I did this I tried downgrading babel and upgrading node etc, that did not work for me

      我所做的是卸载 nodejs 并从 AppData 中删除 npm 和 npm-cache 文件夹 并重新启动。 然后重新安装nodejs。

      瞧,它起作用了

      【讨论】:

      • 我刚刚卸载了 Node.js,然后在上一个 TLS 版本中安装了 node.js,并删除了 C:\Users\my_user\AppData\Roaming 中的那些 npm 文件夹,瞧!
      【解决方案4】:

      在packege.json中添加

      "@babel/preset-env": "^7.2.0"

      【讨论】:

        猜你喜欢
        • 2019-03-06
        • 2016-10-30
        • 2020-02-25
        • 2019-05-26
        • 2019-08-07
        • 2021-04-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多