Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module not found: Error: Can't resolve 'module' in 'node_modules/testdouble/lib' #531

Open
patrick99e99 opened this issue Jun 6, 2024 · 2 comments

Comments

@patrick99e99
Copy link

I have an angular app, and testdouble in my devDependencies of my package file. When I try to run my angular test suite, I am getting:

./node_modules/testdouble/lib/can-register-loader.js:1:15-32 - Error: Module not found: Error: Can't resolve 'module' in '/path/to/project/node_modules/testdouble/lib'

literally require('module'); is breaking...

I am wondering why this isn't an internal dependency of testdouble?

@Michael-Ziluck
Copy link

Please fix this!

@rosston
Copy link
Member

rosston commented Nov 2, 2024

I don't have any solutions here. But I might be able to point in the right direction. I assume you're running your tests in the browser via Karma? And that you're trying to use td.replaceEsm?

require('module') is breaking because it's trying to require the built-in Node.js module, probably because you're in a browser environment. From the replaceEsm docs, I think it pretty much relies on running within Node.js.

It'd be pretty easy to resolve that issue within can-register-loader.js by wrapping in a try/catch. But then you'll have other issues, since it looks like quibble (what testdouble.js uses for module mocking) also depends on core Node.js modules.

The short answer is that you'll probably be happier if you don't try to use replaceEsm in the browser. And probably only use replace to replace properties, not modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants