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

[Bug]: ESM, typescript: importing attributes from package.json causes failing to start test suites #15353

Open
yarick123 opened this issue Oct 22, 2024 · 0 comments

Comments

@yarick123
Copy link

Version

29.7.0

Steps to reproduce

use ESM module,
use the latest typescript version - 5.6.3,
set "resolveJsonModule": true in the tsconfig.json,
in an source file with the tested functionality put something like this:

import { name } from '../package.json' with { type: 'json' };

console.log(name);

start a test suit, which tests functionality in the file changed before

Expected behavior

tests from the test suit are started

Actual behavior

● Test suite failed to run

SyntaxError: The requested module '../package.json' does not provide an export named 'name'

  at Runtime.linkAndEvaluateModule (../../../../node_modules/jest-runtime/build/index.js:708:5)

Additional context

workaround: instead of the named import, import whole json object:

import pkgJson from '../package.json' with { type: 'json' };

console.log(pkgJson.name);

Environment

System:
  OS: Ubuntu 24.04.1 LTS
  CPU: (16) AMD Ryzen 7 PRO 6850U
Binaries:
  Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
  npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
npmPackages:
  jest: 29.7.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant