30
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

error /node_modules/node-sass: Command failedの解決策

Last updated at Posted at 2021-12-17

タイトルの通り、/node_modules/node-sass: Command failedのエラーが発生し、うまくWebpackが動作せずWebpacker::Manifest::MissingEntryErrorが発生しました。

その解決方法を残しておきます。

環境

ruby 2.7.2
rails 6.0.3.4
node --version v16.0.0

エラー内容

bundle exec rails webpacker:installコマンドを実行するとこのようなエラーが出ました。

error /Users/xxx/xxx/xxx/node_modules/@rails/webpacker/node_modules/node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments: 
Directory: /Users/xxx/xxx/xxx/node_modules/@rails/webpacker/node_modules/node-sass

状況

package.jsonには本来あるはずの以下の記述がありませんでした。

"@rails/webpacker": "5.4.3",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12",
"node-sass": "^7.0.0",

変更内容

1 webpacker

まずは、Gemfileを変更しwebpacekrのバージョンを変更しました


gem 'webpacker', '~> 4.0'


gem 'webpacker', '~> 5.0'

2 yarn.lock or package.lock.jsonを削除

次に、yarn.lock または package.lock.jsonを削除します

3 package.json

次に、package.jsonに"@rails/webpacker": "5.4.3"を追記します。

4 yarn install

$ yarn installを実行します

5 yarn add node-sass

$ yarn add node-sass

以上の手順でうまくwebpackerが動作するようになりました。

30
21
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?