webpack-contrib/style-loader

TypeError: this.getOptions is not a function

yelvert opened this issue Β· 19 comments

Module build failed (from ./node_modules/style-loader/dist/cjs.js):
TypeError: this.getOptions is not a function
at Object.loader (.../node_modules/style-loader/dist/index.js:18:24)

It looks like #501 dropped loader-utils as a dependency where this function came from, and instead tries to call this.getOptions which doesnt exist.

npm i style-loader@2.0.0 -D

You need webpack v5 to use the latest version of style-loader, please read changelog

I'm getting this error when using Webpack 5.59.1 and the latest version of style-loader. Do I still need to downgrade to style-loader@2? (Also happens with Webpack 5 and style-loader 2.)

Run npm ls style-loader

Gives the return style-loader@3.3.1.

Do you have thread-loader?

Downgrading Webpack to 4 and style-loader to 2 resolves it. (I write β€œresolves it” but it's obviously not a solution.)

Run npm ls webpack when you try to upgrade to webpack v5

β”œβ”€β”¬ @wordpress/dependency-extraction-webpack-plugin@3.1.4
β”‚ └─┬ webpack@5.39.1
β”‚   └─┬ terser-webpack-plugin@5.1.3
β”‚     └── webpack@5.39.1 deduped
β”œβ”€β”¬ babel-loader@8.2.2
β”‚ └── webpack@5.39.1 deduped
β”œβ”€β”¬ css-loader@5.2.6
β”‚ └── webpack@5.39.1 deduped
β”œβ”€β”¬ style-loader@2.0.0
β”‚ └── webpack@5.39.1 deduped
β”œβ”€β”¬ svg-url-loader@7.1.1
β”‚ β”œβ”€β”¬ file-loader@6.2.0
β”‚ β”‚ └── webpack@5.39.1 deduped
β”‚ └── webpack@5.39.1 deduped
└─┬ webpack-stream@6.1.2
  └─┬ webpack@4.46.0
    └─┬ terser-webpack-plugin@1.4.5
      └── webpack@4.46.0 deduped

Problem in webpack-stream, as you can see it install webpack v4...

...and with style-loader@3:

β”œβ”€β”¬ @wordpress/dependency-extraction-webpack-plugin@3.1.4
β”‚ └─┬ webpack@5.39.1
β”‚   └─┬ terser-webpack-plugin@5.1.3
β”‚     └── webpack@5.39.1 deduped
β”œβ”€β”¬ babel-loader@8.2.2
β”‚ └── webpack@5.39.1 deduped
β”œβ”€β”¬ css-loader@5.2.6
β”‚ └── webpack@5.39.1 deduped
β”œβ”€β”¬ style-loader@3.3.1
β”‚ └── webpack@5.39.1 deduped
β”œβ”€β”¬ svg-url-loader@7.1.1
β”‚ β”œβ”€β”¬ file-loader@6.2.0
β”‚ β”‚ └── webpack@5.39.1 deduped
β”‚ └── webpack@5.39.1 deduped
└─┬ webpack-stream@6.1.2
  └─┬ webpack@4.46.0
    └─┬ terser-webpack-plugin@1.4.5
      └── webpack@4.46.0 deduped

Update webpack-stream to v7

Bingo. Perfect. Thanks!

You need webpack v5 to use the latest version of style-loader, please read changelog

Thanks man, it helped me a lot! <3

./src/index.css
TypeError: this.getOptions is not a function

i m getting this error while executing please help me out

dep commented

I am also getting the issue above. how to solve issue?

take your laptop and throw it into the ocean.

seriously though, i have the same problem.

Have you read the comments above which show the solution?

ERROR in ./app/javascript/stylesheets/application.scss (./node_modules/css-loader/dist/cjs.js??ref--6-1!./node_modules/postcss-loader/dist/cjs.js??ref--6-2!./node_modules/sass-loader/dist/cjs.js??ref--6-3!./app/javascript/stylesheets/application.scss)
Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
TypeError: this.getOptions is not a function
at Object.loader (/home/yash/Desktop/rails_project/granite/node_modules/postcss-loader/dist/index.js:28:24)