繁体   English   中英

Angular 无法运行我的 ng 服务 - Sass 加载程序错误

[英]Angular won't run my ng serve - Sass Loader error

I had to reformat my windows C drive and reinstall windows now suddenly all of my angular projects I'm working on are having this issue. 我已经厌倦了几件事来尝试修复它,例如删除应用程序中的节点模块文件夹,但似乎没有任何效果。

我已经尝试过这些修复方法,但都失败了:

npm install --save-dev webpack webpack-dev-server css-loader sass-loader node-sass extract-loader file-loader

npm install --save-dev --unsafe-perm node-sass

ERROR in ./src/styles.scss (./node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!./node_modules/postcss-loader/src??embedded!./node_modules/sass-loader/dist/cjs.js??ref--14-3!./src/styles.scss)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
ValidationError: Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema.
 - options has an unknown property 'includePaths'. These properties are valid:
   object { implementation?, sassOptions?, prependData?, sourceMap?, webpackImporter? }
    at validate (E:\Work\MyApp\Eng\stage\frontend\MyApp\node_modules\sass-loader\node_modules\schema-utils\dist\validate.js:50:11)
    at Object.loader (E:\Work\MyApp\Eng\stage\frontend\MyApp\node_modules\sass-loader\dist\index.js:36:28)
ERROR in ./src/app/app.component.scss
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
ValidationError: Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema.
 - options has an unknown property 'includePaths'. These properties are valid:
   object { implementation?, sassOptions?, prependData?, sourceMap?, webpackImporter? }
    at validate (E:\Work\MyApp\Eng\stage\frontend\MyApp\node_modules\sass-loader\node_modules\schema-utils\dist\validate.js:50:11)
    at Object.loader (E:\Work\MyApp\Eng\stage\frontend\MyApp\node_modules\sass-loader\dist\index.js:36:28)
ERROR in ./src/app/welcome/welcome.component.scss
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
ValidationError: Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema.
 - options has an unknown property 'includePaths'. These properties are valid:
   object { implementation?, sassOptions?, prependData?, sourceMap?, webpackImporter? }
    at validate (E:\Work\MyApp\Eng\stage\frontend\MyApp\node_modules\sass-loader\node_modules\schema-utils\dist\validate.js:50:11)
    at Object.loader (E:\Work\MyApp\Eng\stage\frontend\MyApp\node_modules\sass-loader\dist\index.js:36:28)

这可能是因为在安装新的 Windows 之前,您有不同版本的 Node.js。 您下载了最新的节点,但您的 node-sass 仍在尝试使用旧版本进行构建。 尝试“ npm rebuild node-sass --force ”。 运行此程序后,您的应用程序应该可以工作。

就我而言,问题是我明确安装了:

  • node-sass
  • css-loader
  • sass-loader
  • style-loader

因此它们被列在package.json开发依赖项中。 从那里删除它们后,删除node_modulesnpm install ,我的 Angular 应用程序再次运行。

我可以想象 Angular 使用自己版本的这些软件包,并且在package.json (可能是另一个版本)中明确安装它们时,它会遇到这些问题(我可能是一个假设)。

它可以解释为什么交换 OP 的package.json也对他有用。

我解决了删除 node_modules 文件夹的问题(您可以使用 cmd 来解决,所以不会花这么长时间),然后再次 npm i,然后 npm i -S node-!

如果你的项目名为“MyApp”,那么我认为你能做的最好的事情就是重新开始,慢慢地将你的代码一个一个地复制到新项目中。

这也可能有帮助: https://medium.com/@manivel45/configuring-angular-7-project-with-sass-bootstrap-and-angular-material-design-69b0f033dc04

我完全不确定哪个项目在这里帮助最大,因为上面发布的所有信息都非常有用。 Ultimately deleting the package.json lock file and then completely replacing the package.json file with a separate Json file that worked on another project seems to have fixed the issue. 删除 node_modules 文件夹,然后运行 npm 安装。 谢谢你们每一个人的帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM