【ERROR in Cannot find module 'node-sass'】【this.getResolve is not a function】

在安裝sass插件時報錯

$ npm install sass-loader node-sass --save-dev

//返回的報錯信息
npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path C:\Users\jinwe\truth_hold\node_modules\node-sass\node_modules
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, mkdir 'C:\Users\jinwe\truth_hold\node_modules\node-sass\node_modules'
npm ERR!  [OperationalError: EPERM: operation not permitted, mkdir 'C:\Users\jinwe\truth_hold\node_modules\node-sass\node_modules'] {
npm ERR!   cause: [Error: EPERM: operation not permitted, mkdir 'C:\Users\jinwe\truth_hold\node_modules\node-sass\node_modules'] {
npm ERR!     errno: -4048,
npm ERR!     code: 'EPERM',
npm ERR!     syscall: 'mkdir',
npm ERR!     path: 'C:\\Users\\jinwe\\truth_hold\\node_modules\\node-sass\\node_modules'
npm ERR!   },
npm ERR!   stack: "Error: EPERM: operation not permitted, mkdir 'C:\\Users\\jinwe\\truth_hold\\node_modules\\node-sass\\node_modules'",
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: 'C:\\Users\\jinwe\\truth_hold\\node_modules\\node-sass\\node_modules',
npm ERR!   parent: 'truth_hold'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\jinwe\AppData\Roaming\npm-cache\_logs\2019-11-05T01_54_51_276Z-debug.log

C:\Users\jinwe\truth_hold>npm run dev

> truth_hold@1.0.0 dev C:\Users\jinwe\truth_hold
> node build/dev-server.js wx

 ERROR  Failed to compile with 2 errors

這時運行npm ls,會出現這個下面的錯誤

$ npm ls

//返回的報錯信息
npm ERR! peer dep missing: webpack@^4.36.0, required by sass-loader@8.0.0
npm ERR! peer dep missing: vue-template-compiler@^2.0.0, required by vue-loader@13.7.3

並且啓動項目的時候報錯

$ npm run dev

//返回的錯誤信息,已簡化
ERROR in Cannot find module 'node-sass'
this.getResolve is not a function

這是因爲當前sass的版本太高,webpack編譯時出現了錯誤,這個時候只需要換成低版本的就行
修改package.json文件,將裏面的 "sass-loader"的版本換成更低的版本,比如我現在是"sass-loader": "^8.0.0"換成了"sass-loader": "^7.3.1"

重新安裝sass,再啓動項目就成功了

//重新安裝sass
$ npm install sass-loader node-sass --save-dev

//啓動項目
$ npm run dev
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章