Skip to content

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

Closed

Description

@patrick99e99

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?

Activity

  1. Michael-Ziluck commented on Aug 29, 2024

    @Michael-Ziluck

    Please fix this!

  2. rosston commented on Nov 2, 2024

    @rosston
    Member

    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.

  3. added a commit that references this issue on Oct 12, 2026
    ec31f1b
  4. rosston commented on Oct 12, 2026

    @rosston
    Member

    Fixed in #548 and released in 4.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions