9

I'm having a problem that is happening to me in two differentes PC's. For my project I've installed for development the following dependencies: (webpack webpack-cli @babel/core @babel/preset-env @babel/preset-react babel-loader css-loader style-loader html-webpack-plugin) and react & react-dom. The trouble comes when I try to import some stylesheet in any component of my project, the error is: import api from "!../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js";. I'm little confused because I checked many times other webpack configurations done by myself and they are the same that I am using now. What is your advice? Thank you!

2
  • You will need a separate loader for importing stylesheets, e.g. postcss. Commented Jan 27, 2021 at 14:43
  • I tried but it didn't work. In previous projects I worked with css and webpack, importing styles from react components and had no problem. Any other idea? Commented Jan 27, 2021 at 16:24

1 Answer 1

1

I had this issue, seems that webpack does not allow multiple definitions of the styles css file. So, what solved the issue for me is remove the css file from "styles" in angular.json

    //....
    "architect": {
    "build": {
      "builder": "@angular-builders/custom-webpack:browser",
      "options": {
        "outputPath": "dist/app-name",
        "index": "src/index.html",
        "main": "src/app/main.ts",
        "polyfills": "src/app/polyfills.ts",
        "tsConfig": "tsconfig.json",
        "preserveSymlinks": true,
        "assets": [
          "src/client/img"
        ],
        "styles": [], //don't mention your styles.css here
        "scripts": [],
        //....

webpack.config.js should include the loaders and it should be enough

      {
          test: /\.css$/,
          use: ['style-loader', 'css-loader']
      },
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.