question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error "module build failed" when importing with @angular/cli

See original GitHub issue

What MDC-Web Version are you using?

0.3.10

What browser(s) is this bug affecting?

All

What OS are you using?

Linux (Fedora 23), Node v6.11.0, npm v5.2.0

What are the steps to reproduce the bug?

Start an @angular/cli project, install for instance @material/select, and add following to styles.scss.

@import '~@material/select/mdc-select';

Run project with npm start

What is the expected behavior?

It should compile fine.

What is the actual behavior?

The following error is output:

ERROR in ./~/css-loader?{"sourceMap":false,"importLoaders":1}!./~/postcss-loader?{"ident":"postcss"}!./~/@angular/cli/~/sass-loader/lib/loader.js?{"sourceMap":false,"precision":8,"includePaths":[]}!./src/styles.scss
Module build failed: 
@import "@material/animation/functions";
^
      File to import not found or unreadable: @material/animation/functions.
Parent style sheet: /workspace/WISTWFU/wist-wfu-app/frontend/frontend-js/node_modules/@material/select/mdc-select.scss
      in /workspace/WISTWFU/wist-wfu-app/frontend/frontend-js/node_modules/@material/select/mdc-select.scss (line 17, column 1)
 @ ./src/styles.scss 4:14-215
 @ multi ./~/primeng/resources/primeng.min.css ./src/styles.scss
webpack: Failed to compile.

Any other information you believe would be useful?

A simple modification of the mdc-select.scss file makes it possible to import it correctly: Simply adding ~ to the package imports.

@import "~@material/animation/functions";
@import "~@material/typography/mixins";
@import "~@material/theme/mixins";
@import "~@material/rtl/mixins";

However I’m hesitant to submit my own pull request, since it would impact every component package.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
mischklcommented, Jul 31, 2017

@yeelan0319 unfortunately this does not solve the problem for me, as I am using Angular CLI 😢 And that is actually what this issue is about.

Regarding the documentation: IMHO it’s missing specific information about how to configure Webpack. This seems to be exactly the line I mentioned from material-components’ own webpack.config.js file; modified for end-users I guess it would be something like:

includePaths: glob.sync('node_modules/@material/*').map((d) => path.join(__dirname, d))

Why not include that directly in the README, instead of just a vague statement that node_modules needs to be in the Sass include path?

Likewise for people using node-sass directly - IMHO it would be much more helpful to have a concrete code snippet.

1reaction
patrickgdlcommented, Feb 22, 2019

This one worked for me on Angular 7.x:

 "stylePreprocessorOptions": {
        "includePaths": [
         "node_modules"
        ]
     }

You must nclude the same stylePreprocessorOptions on projects.yourProjectName.architect.build.options and projects.YourProjectName.test.options.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular-cli 25.5 Module build failed - typescript - Stack Overflow
The error says the problem is in app.module. · Make sure you reference all your source files in the "include" and "files" sections...
Read more >
Angular - Code with Mosh Forum
Error : Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js): · delete the node_modules folder · delete package-lock.json ...
Read more >
Module build fails after importing mdb.scss - MDBootstrap
I installed the MDB5 ANGULAR UI KIT Pro Essential and after importing the scss to the styles.css file I get the error shown...
Read more >
Angular compiler options
References created by the template compiler use this module name when importing symbols from the flat module. Ignored if flatModuleOutFile is false ....
Read more >
Angular CLI: "Module not found: Error: Can't resolve..."
The problem. After upgrading one of my Angular applications, from version 5 to version 6, I tried to build it (using ng build...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found