Open noomorph opened 2 years ago
The issue is still relevant, just in case.
I have a similar issue. An npm package requires an script from another npm package :
require('three/examples/js/loaders/FontLoader.js');
The project itself has three
as dependency. But somehow require can't find the script in the three npm package but three itself. I get the error:
Cannot find module 'three/examples/js/loaders/FontLoader.js' from 'node_modules/@wmc/zk-web3d/dist/es5/services/FontManager.js'
My current workaround is to set a moduleNameMapper for the script in the jest.config.js
module.exports = {
...
moduleNameMapper: {
...
'three/examples/js/loaders/FontLoader.js': 'node_modules/three/examples/js/loaders/FontLoader.js'
}
}
It worked with jest 27.5.1 but broke after updated to 28.1.0.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Jest 28.1.3 fails at this example just as it did the first day. 🤷♂️
The issue is relevant.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
This is a bug in resolve.exports
(the lib we use to resolve exports
, which shipped in Jest 28).
const pkg = require('yargs/package.json')
const { resolve } = require('resolve.exports');
console.log(resolve(pkg, 'yargs', { conditions: ['require'], unsafe: true }));
console.log(require.resolve('yargs/yargs'))
Possibly https://github.com/lukeed/resolve.exports/issues/17?
Don't know if this is a good place, I notice if the dependency is:
{
"type": "module",
"exports": "./index.mjs",
"main": "./index.js"
}
jest
will load ./index.mjs
correctly.
But if the dependency is:
{
"type" : "module",
"exports": {
"import": "./index.mjs",
"require": "./index.js"
}
}
jest
will load ./index.js
instead.
It seems I am unable to update another dependency I have because of this bug or jest-cli simply expects an older version of yargs then my updated yarn.lock
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/catalin/Code-WSL/creativeonl/node_modules/string-width/index.js from /home/catalin/Code-WSL/creativeonl/node_modules/cliui/build/index.cjs not supported.
Instead change the require of index.js in /home/catalin/Code-WSL/creativeonl/node_modules/cliui/build/index.cjs to a dynamic import() which is available in all CommonJS modules.
at Object.
My upgrade has a sub dependency resulting in this lock change
Version
28.1.0
Steps to reproduce
You'll see that a vanilla installation of Jest 28 behaves in a drastically different way when it comes to importing
require('yargs/yargs').Parser
.Expected behavior
I'd expect Jest in both cases to find the exported function.
Actual behavior
Jest 28 returns
undefined
on an attempt torequire('yargs/yargs').Parser
.Additional context
I have to say that I can see
node_modules/yargs/yargs
there, a file without an extension. Inside it I see:Maybe there's some problem with the package, with the way how it exports itself. But did you actually intend to introduce a breaking behavior with 28.x compared to 27.x?
Environment