问题
I have a Rails app and something recently changed in such a way that the rails server
will start but when I load a page I get an NPM related error in the browser console. I did not set up NPM/VueJS in this app so need some help getting it running locally...
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 is similar to an issue reported recently in this SO post but in that case NPM wasn't embedded in a Rails app. Regardless I tried their solution by removing node_modules
(there is no package-lock.json
) and running npm install
but that led to more errors in the 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!
This app is working in production so I'm not interested in updating outdated libraries at the moment. I'm not an NPM/JS guru so would appreciate any advice no matter how rudimentary this probably is. Thanks!
Edit: Results of yarn install --check-files
as per request
$ 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.
回答1:
Are you using yarn on your project? If so try:
yarn install --check-files
And please post the result of your terminal.
来源:https://stackoverflow.com/questions/60856624/rails-npm-module-build-failed-err-package-path-not-exported-for-babel-loader