【问题标题】:Rails/NPM - Module build failed [ERR_PACKAGE_PATH_NOT_EXPORTED] for babel-loaderRails/NPM - babel-loader 的模块构建失败 [ERR_PACKAGE_PATH_NOT_EXPORTED]
【发布时间】:2020-07-06 10:59:50
【问题描述】:

我有一个 Rails 应用程序,最近发生了一些变化,rails server 将启动,但是当我加载页面时,我在浏览器控制台中收到与 NPM 相关的错误。我没有在这个应用程序中设置 NPM/VueJS,所以需要一些帮助才能让它在本地运行......

Error: Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main resolved in /Users/meltemi/rails/myapp/node_modules/@babel/helper-compilation-targets/package.json
    at applyExports (internal/modules/cjs/loader.js:524:9)
    at resolveExports (internal/modules/cjs/loader.js:541:12)
    at Function.Module._findPath (internal/modules/cjs/loader.js:661:22)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:963:27)
    at Function.Module._load (internal/modules/cjs/loader.js:859:27)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (/Users/meltemi/rails/myapp/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/Users/meltemi/rails/myapp/node_modules/@babel/preset-env/lib/debug.js:8:33)
    at Module._compile (/Users/meltemi/rails/myapp/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (/Users/meltemi/rails/myapp/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/Users/meltemi/rails/myapp/node_modules/@babel/preset-env/lib/index.js:11:14)
    at Module._compile (/Users/meltemi/rails/myapp/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (/Users/meltemi/rails/myapp/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at requireModule (/Users/meltemi/rails/myapp/node_modules/@babel/core/lib/config/files/plugins.js:165:12)
    at loadPreset (/Users/meltemi/rails/myapp/node_modules/@babel/core/lib/config/files/plugins.js:83:17)
    at createDescriptor (/Users/meltemi/rails/myapp/node_modules/@babel/core/lib/config/config-descriptors.js:154:9)
    at /Users/meltemi/rails/myapp/node_modules/@babel/core/lib/config/config-descriptors.js:109:50
    at Array.map (<anonymous>)
    at createDescriptors (/Users/meltemi/rails/myapp/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPresetDescriptors (/Users/meltemi/rails/myapp/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
    at presets (/Users/meltemi/rails/myapp/node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
    at mergeChainOpts (/Users/meltemi/rails/myapp/node_modules/@babel/core/lib/config/config-chain.js:320:26)
    at /Users/meltemi/rails/myapp/node_modules/@babel/core/lib/config/config-chain.js:283:7
    at Generator.next (<anonymous>)
    at buildRootChain (/Users/meltemi/rails/myapp/node_modules/@babel/core/lib/config/config-chain.js:90:27)
    at buildRootChain.next (<anonymous>)
    at loadPrivatePartialConfig (/Users/meltemi/rails/myapp/node_modules/@babel/core/lib/config/partial.js:95:62)
    at loadPrivatePartialConfig.next (<anonymous>)

这与最近在 this SO post 中报告的问题相似,但在这种情况下,NPM 并未嵌入到 Rails 应用程序中。不管我尝试了他们的解决方案,删除了node_modules(没有package-lock.json)并运行npm install,但这会导致shell中出现更多错误:

$ npm install
npm WARN deprecated postcss-cssnext@3.1.0: 'postcss-cssnext' has been deprecated in favor of 'postcss-preset-env'. Read more at https://moox.io/blog/deprecating-cssnext/
npm WARN deprecated mkdirp@0.5.4: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm ERR! code 1
npm ERR! Command failed: git checkout ^2.4.0
npm ERR! error: pathspec '^2.4.0' did not match any file(s) known to git
npm ERR!

这个应用程序正在生产中,所以我目前对更新过时的库不感兴趣。我不是 NPM/JS 专家,所以无论这可能多么初级,我都会很感激任何建议。谢谢!

编辑:yarn install --check-files 根据请求的结果

$ yarn install --check-files
yarn install v1.22.4
[1/5] ????  Validating package.json...
[2/5] ????  Resolving packages...
[3/5] ????  Fetching packages...
[4/5] ????  Linking dependencies...
[5/5] ????  Building fresh packages...
$ node -e "try { require('fs').symlinkSync('../../node_modules/@bower_components', 'vendor/assets/components', 'junction') } catch (e) { }"
✨  Done in 10.22s.

【问题讨论】:

  • 您使用的是 Linux 还是 Mac?
  • MacOS (10.15.4)

标签: ruby-on-rails npm babeljs npm-install


【解决方案1】:

您在项目中使用纱线吗?如果是这样试试:

yarn install --check-files

请发布您的终端结果。

【讨论】:

  • 以上yarn install --check-files 的结果。还尝试删除node_modules 文件夹并再次运行yarn install...无济于事。
  • 去掉node_modules还不够,还需要去掉yarn.lock
【解决方案2】:

这是我的情况,只需删除 node_modules 和 package-lock.json 并运行 npm installso npm run build 正常工作。show here for this answer

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-17
    • 2023-03-28
    • 2019-12-15
    • 2019-08-01
    • 1970-01-01
    • 2016-02-22
    • 2021-11-26
    • 2019-12-26
    相关资源
    最近更新 更多