0
0

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 3 years have passed since last update.

【Rails】 Cannot assign to read only property 'exports' 【webpacker】

Posted at

問題

RailsでとあるNodeモジュールを入れたらブラウザ上で

Cannot assign to read only property 'exports'

っていうエラーが出た。調べると"module.exportsとimportを同時に使うとエラーになるぞ"という情報が出てくるのだが、別にそういうわけではない。

解決策

色々調べてるとこんな情報が出てきた。

I suspect @rails/webpacker v6 (not yet released) will fix this issue, because it drops the "nodeModules" loader completely. See changelog

実際にやってみたところ確かに出なくなった。

結論

原因はよくわからないがnodeModulesローダーがnode_moduls/以下をトランスパイルしてるせいでたまに出るエラーらしい。上の通りWebpacker 6からはデフォルトで削除されている。ビルドも軽くなるし一石二鳥。

config/webpack/environment.js
const { environment } = require('@rails/webpacker')

environment.loaders.delete('nodeModules')
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?