ts-loader: Module build failed: TypeError: loaderUtils.getOptions is not a function
I am trying to import a TS project in my JS project using ts-loader, but I am getting the following error. What can be the issue in this case?
Module build failed: TypeError: loaderUtils.getOptions is not a function
at getLoaderOptions (C:\Users\Sujit\Desktop\Projects\MyProj-Webpack\node_modules\ts-loader\dist\index.js:61:36)
at Object.loader (C:\Users\Sujit\Desktop\Projects\MyProj-Webpack\node_modules\ts-loader\dist\index.js:15:19)
webpack: Failed to compile.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 32
- Comments: 25 (3 by maintainers)
Commits related to this issue
- chore: downgrade ts-loader to 8 https://github.com/TypeStrong/ts-loader/issues/595#issuecomment-824240989 — committed to nuxt/image by pi0 3 years ago
- Upgrade all dev dependencies I was running into cryptic build errors that seemed related to old versions of dev dependencies, specifically this one for an old version of webpack (two major versions b... — committed to azavea/loam by pcaisse 3 years ago
- fixed build issue by downgrading ts loader, see https://github.com/TypeStrong/ts-loader/issues/595 — committed to andSubmarine/andsubmarine.github.io by andSubmarine 3 years ago
- Downgrade ts-loader https://github.com/TypeStrong/ts-loader/issues/595 — committed to n8n-io/n8n by ivov 3 years ago
- chore: downgrade ts-loader to 8 https://github.com/TypeStrong/ts-loader/issues/595#issuecomment-824240989 — committed to procrates/nuxt-image by pi0 3 years ago
ts-loader 9 doesn’t support webpack 4: https://github.com/TypeStrong/ts-loader/releases/tag/v9.0.0
If you’re still using Webpack 4, or Node <12, try using
ts-loader v8.2.0
it looks like it’s the last version with Webpack 4 compatibility: https://github.com/TypeStrong/ts-loader/releases/tag/v8.2.0I just had this problem too. In my case, it was caused by an older version of the
loader-utils
package in node_modules.ts-loader
depends on this package, and older versions don’t have thegetOptions
function.You could manually add a more recent version of
loader-utils
to your project (npm install loader-utils@latest
) or try deleting node_modules and running npm/yarn install to rebuild your dependencies.i am getting same error, now what is the work around? “webpack”: “^5.35.1”,node version:12.18.1
@creativecoder I tried updating to the latest version, but I am still getting the same error. @johnnyreilly What exactly do you need? Steps to reproduce the error?
Syntax Error: TypeError: loaderContext.getOptions is not a function
@ multi (webpack)-dev-server/client?http://192.168.43.215:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.ts
I am currently encountering this challenge when migrating vue2 to vue3 with typescript, does anyone have an insight on this, kindly assist.
I’m getting this error with what I believe are correct versions for webpack 5 with workspaces in Npm@7
I’ve gotten the error to intermittently go away… Not sure how. Might have been a different error with higher priority too.
Update
Something in the top level npm workspace was installing webpack 4 and
webpack-cli
was picking that up and running with it. Hope this helps someone that runs into similar and ends up here.Just saw that error. Was because I had an older version of
loader-utils
installed, so upgraded it and the error went away.Module build failed: TypeError: loaderUtils.getOptions is not a function
The same error with the same tool set: ts-loader@9.2.6 with webpack@5.67.0 and happypack@5.0.1
I’m getting “loaderContext.getOptions is not a function” now in ts-loader 9.0.2 with webpack 4.44, typescript 4.2.3, and loader-utils 2.0.0. I just upgraded to hopefully fix a different set of problems, so I have no real working configuration to go back to or compare. I’m wondering if my timing is coincidental with some breaking change.
@psujit Can you confirm that in your project you have
node_modules/loader-utils/lib/getOptions.js
and a reference togetOptions
innode_modules/loader-utils/lib/index.js
?If runtime is complaining
getOptions
is not a function, it’s probably not (there)…I think this happens a lot. I’m tempted to add a warning to the console (or even a hard error) to say “you’re not using webpack 5 - you need to”.