ts-jest says `The requested module 'yargs/helpers' does not provide an export named 'hideBin'`
See original GitHub issueHi, I have a question.
I’m going to use yargs in the project have ts-jest.
ts-jest said The requested module 'yargs/helpers' does not provide an export named 'hideBin'
but I know yargs/helper
have export function hideBin
🐚 log
yarn run v1.22.17
$ node --experimental-vm-modules node_modules/jest/bin/jest.js
(node:22533) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
FAIL src/main.spec.ts
● Test suite failed to run
SyntaxError: The requested module 'yargs/helpers' does not provide an export named 'hideBin'
at Runtime.linkAndEvaluateModule (node_modules/jest-runtime/build/index.js:779:5)
at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
at runJest (node_modules/@jest/core/build/runJest.js:401:19)
at _run10000 (node_modules/@jest/core/build/cli/index.js:320:7)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.485 s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
This script that imported in main.spec.ts invoked this error.
setup.ts
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import path from "path";
import dotenv from "dotenv";
const __dirname = path.dirname(new URL(import.meta.url).pathname);
dotenv.config({ path: path.resolve(__dirname, "../.env") });
const args = yargs(hideBin(process.argv)).parse();
export default args;
I solved this problem not importing hideBin.
setup.ts (resolved problem)
import yargs from "yargs";
import path from "path";
import dotenv from "dotenv";
const __dirname = path.dirname(new URL(import.meta.url).pathname);
dotenv.config({ path: path.resolve(__dirname, "../.env") });
const args = yargs(process.argv.slice(2)).parse();
export default args;
It’s mysterious. Someone knows why this problem happen?
I’m using this jest.config.js
module.exports = {
// [...]
preset: "ts-jest/presets/default-esm", // or other ESM presets
globals: {
"ts-jest": {
useESM: true,
},
},
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
};
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Jest, ES6 modules "does not provide export named"
The problem I have is that my app is built with ES6 modules and Jest ES6 modules is experimental and it seems that...
Read more >the requested module 'path' does not provide an export ...
ts -jest said The requested module 'yargs/helpers' does not provide an export named 'hideBin' but I know yargs/helper have export function hideBin.
Read more >The requested module does not provide an export named in JS
The "Ucaught SyntaxError: The requested module does not provide an export named" occurs when mixing up default and named ES6 module imports and...
Read more >Additional documentation - yargs - JS.ORG
Calling .parse() with no arguments is equivalent to calling .argv : ... Note: Yargs exposes the helper hideBin , which handles the process.argv.slice...
Read more >Настройка Jest
To read TypeScript configuration files Jest requires ts-node . Make sure it is installed in ... Node.js core modules, like fs , are...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@AndyClausen I believe the ESM version of yargs drops the magic
.argv
accessor, try the following:.parse()
is equivalent to.argv
but less magic.https://github.com/facebook/jest/issues/12284
Already did it thank you