看网上大多数文章都是建议降低nodejs版本!其实可以通过匹配对应的node-sass和sass-loader版本来解决兼容性问题。尽量使用新的版本!
问题一:Node Sass version 7.0.1 is incompatible with ^4.0.0.
可以通过升级 sass-loader 的版本解决。
问题二:TypeError: this.getOptions is not a function。
sass-loader 版本太高,可以通过降低版本解决。
===========>然后翻阅了 sass-loader 的 github [ https://github.com/webpack-contrib/sass-loader/releases/tag/v11.0.0 ]
发现 sass-loader@11.0.0 版本需要 webpack@5.0.0 ,而 @vue/cli@4.5.0 所用的是 webpack@4,所以需要将 sass-loader的版本降到11以下。(转自:[解决]TypeError: this.getOptions is not a function - 简书)
===========>node-sass 和 node 的版本匹配关系通过github获取。(https://github.com/sass/node-sass)
Node 17 | 7.0+ | 102 |
Node 16 | 6.0+ | 93 |
Node 15 | 5.0+, <7.0 | 88 |
Node 14 | 4.14+ | 83 |
Node 13 | 4.13+, <5.0 | 79 |
Node 12 | 4.12+ | 72 |
Node 11 | 4.10+, <5.0 | 67 |
Node 10 | 4.9+, <6.0 | 64 |
Node 8 | 4.5.3+, <5.0 | 57 |
Node <8 | <5.0 | <57 |
最后的版本组合:
node v16.13.1
"node-sass": "^6.0.1"
"sass-loader": "^10.2.0"