首页 > 解决方案 > Angular 通用:找不到或无法读取要导入的文件:~src/main.scss

问题描述

我创建了一个新项目ng new并运行了以下命令(ref):

  1. ng add @nguniversal/express-engine --clientProject my-project-name
  2. npm run build:ssr && npm run serve:ssr

这启用了端口 4000 上的服务器端渲染。

到目前为止一切都很好。

现在我添加了一个main.scss. 然后在 中my app.component.scss,我使用语法导入tilde如下:

@import "~src/main.scss";

现在运行时npm run build:ssr && npm run serve:ssr出现以下错误:

ERROR in Module build failed (from ./node_modules/sass-loader/lib/loader.js):

@import "~src/main.scss";
^
      File to import not found or unreadable: ~src/main.scss.
      in D:\nodebook2\angular-universal-test\src\app\app.component.scss (line 1, column 1)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! angular-universal-test@0.0.0 build:client-and-server-bundles: `ng build --prod && ng run angular-universal-test:server:production`

~src除了用“常规”路径替换之外的任何解决方法?(我有100个组件的项目,全部~src用于导入scss文件)

标签: angular

解决方案


推荐阅读