Skip to content

[Help] runtime node_module loading in PnP mode #3368

@Eomm

Description

@Eomm

Hi,
I'm writing some unit tests to check if my-module loads correctly a user-land module external-module:

const myMod = require('my-module')

myMod( { load: 'external-module' } )

Right now I'm having the error:

Your application tried to access transport, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.  Required package: transport Required by: /Users/mspigolon/workspace/pino/test/  Require stack: - /Users/mspigolon/workspace/pino/test/transport.test.js

This is loud and clear because of the test that creates at runtime the test dependency

  await symlink(
    join(__dirname, 'fixtures', 'transport'),
    join(__dirname, '..', 'node_modules', 'transport')
  )

I cannot find a way to say to [email protected] to do the fallback to the filesystem.
I read about the PnPApi but I did not figure out how to use them to load this dependency created at runtime. Could you help me? Is it the right choice or do you see a better way?

Another solution would be to publish the test-transport-module and install it in my opinion, but I would avoid it.

My yarnrc is quite straightforward:

yarnPath: ".yarn/releases/yarn-berry.cjs"
nodeLinker: pnp
pnpMode: loose

Thks

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