最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error: Cannot find module '@railswebpacker' rails 6 - Stack Overflow

programmeradmin0浏览0评论

When I run my Rails 6.0 application on development environment I get the next trace on the development.log

[Webpacker] Compiling…
[Webpacker] Compilation failed:
/home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:93
                throw err;
                ^

Error: Cannot find module '@rails/webpacker'
Require stack:
- /mnt/config/webpack/environment.js
- /mnt/config/webpack/development.js
- /home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js
- /home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js
- /home/alejo/rails_project/node_modules/webpack/bin/webpack.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:954:17)
    at Function.Module._load (internal/modules/cjs/loader.js:847:27)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/mnt/config/webpack/environment.js:1:87)
    at Module._compile (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/mnt/config/webpack/development.js:3:21)
    at Module._compile (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at WEBPACK_OPTIONS (/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:114:13)
    at requireConfig (/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:116:6)
    at /home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:123:17
    at Array.forEach (<anonymous>)
    at module.exports (/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:121:15)
    at /home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:71:45
    at Object.parse (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/yargs/yargs.js:567:18)
    at /home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:49:8
    at Object.<anonymous> (/home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:366:3)
    at Module._compile (internal/modules/cjs/loader.js:1121:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/mnt/config/webpack/environment.js',
    '/mnt/config/webpack/development.js',
    '/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js',
    '/home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js',
    '/home/alejo/rails_project/node_modules/webpack/bin/webpack.js'
  ]
}

I am using webpacker 4.0.7, rails 6.0.0 and ruby 2.6.5

I want to know why am I getting this error and how do I solve it.

Thank you

When I run my Rails 6.0 application on development environment I get the next trace on the development.log

[Webpacker] Compiling…
[Webpacker] Compilation failed:
/home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:93
                throw err;
                ^

Error: Cannot find module '@rails/webpacker'
Require stack:
- /mnt/config/webpack/environment.js
- /mnt/config/webpack/development.js
- /home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js
- /home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js
- /home/alejo/rails_project/node_modules/webpack/bin/webpack.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:954:17)
    at Function.Module._load (internal/modules/cjs/loader.js:847:27)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/mnt/config/webpack/environment.js:1:87)
    at Module._compile (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/mnt/config/webpack/development.js:3:21)
    at Module._compile (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at WEBPACK_OPTIONS (/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:114:13)
    at requireConfig (/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:116:6)
    at /home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:123:17
    at Array.forEach (<anonymous>)
    at module.exports (/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:121:15)
    at /home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:71:45
    at Object.parse (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/yargs/yargs.js:567:18)
    at /home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:49:8
    at Object.<anonymous> (/home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:366:3)
    at Module._compile (internal/modules/cjs/loader.js:1121:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/mnt/config/webpack/environment.js',
    '/mnt/config/webpack/development.js',
    '/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js',
    '/home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js',
    '/home/alejo/rails_project/node_modules/webpack/bin/webpack.js'
  ]
}

I am using webpacker 4.0.7, rails 6.0.0 and ruby 2.6.5

I want to know why am I getting this error and how do I solve it.

Thank you

Share Improve this question asked Mar 2, 2020 at 15:19 Alejo DevAlejo Dev 2,5866 gold badges34 silver badges49 bronze badges 4
  • Is there an @rails directory in the node_modules directory? – Michael Chaney Commented Mar 2, 2020 at 15:22
  • Yes, it is, and there is a webpacker directory inside it – Alejo Dev Commented Mar 2, 2020 at 15:22
  • 1 what is your project layout? why is your config directory in /mnt? – rossta Commented Mar 4, 2020 at 2:17
  • I had the config folder on another location and I had a symbolic link, I solved the problem by moving the config folder to the project folder – Alejo Dev Commented Mar 4, 2020 at 18:29
Add a comment  | 

1 Answer 1

Reset to default 17

I ran into this issue as well. For me, the issue was the node version (13.6.0). I figured this out by running yarn add @rails/webpacker, which returned the error Expected version "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7". Got "13.6.0"

To fix it:

  1. Update node to an appropriate version (see error above)
  2. Delete node_modules directory
  3. Update yarn files with yarn install --check-files
  4. Install webpacker with rails webpacker:install
  5. Confirm it worked by bin/webpack-dev-server and getting no errors
发布评论

评论列表(0)

  1. 暂无评论