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

@tsconfig/node22/tsconfig.json uses the wrong module and moduleResolution!?! #279

Open
khteh opened this issue Oct 16, 2024 · 9 comments · May be fixed by #301
Open

@tsconfig/node22/tsconfig.json uses the wrong module and moduleResolution!?! #279

khteh opened this issue Oct 16, 2024 · 9 comments · May be fixed by #301

Comments

@khteh
Copy link

khteh commented Oct 16, 2024

I hit the following error with node22 base:

 Exception during run: error TS5110: Option 'module' must be set to 'Node16' when option 'moduleResolution' is set to 'Node16'.

Why Node16? Shouldn't it be Node22 or NodeNext?

@orta
Copy link
Member

orta commented Oct 31, 2024

node22 doesn't exist, there's not been significant changes to the module system since node16 to my knowledge

@daviduzumeri
Copy link

Now that TS 5.8 has hit final release, we're seeing some differences between node16 and nodenext (as well as between node18 and nodenext), especially around requiring ESM modules. The 5.8 release notes (at least for the RC, I don't think the final ones are up yet but I can't imagine we'll see much difference) are recommending nodenext for Node 22 users: https://devblogs.microsoft.com/typescript/announcing-typescript-5-8-rc/#support-for-require()-of-ecmascript-modules-in---module-nodenext

This is like the opposite of A Big Deal but was reading the release notes and came to check on this repo figured I'd at least bring it up for discussion. (We switched to native ESM a while ago and haven't looked back; it works beautifully.)

@vladshcherbin
Copy link

node 18+ configs should definitely be updated to reflect TS team recommendations from TS 5.8 post

@khteh
Copy link
Author

khteh commented Mar 1, 2025

$ node --version
v23.7.0

"typescript": "^5.8.2"

I still get the following error when running test script:

"ts_test": "export NODE_ENV=development && env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' ./node_modules/.bin/nyc --timeout 10000 --recursive --check-leaks --reporter=lcov --reporter=text --reporter=text-summary --reporter=html ./node_modules/.bin/mocha --loader=ts-node/esm -r ts-node/register tests/**/*.ts --reporter mocha-junit-reporter --reporter-options mochaFile=test_reports/mocha/test-results.xml --exit",
 Exception during run: error TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'.

When I switch to env TS_NODE_COMPILER_OPTIONS='{\"module\": \"NodeNext\" }' , or removing this env altogether, I get different error:

 Exception during run: file:///usr/src/Node.JSRestAPI/src/webapi/routes/api.ts:14
import { StudentRepository, TeacherRepository, LoggerImpl, DatabaseTypes, Database } from "infrastructure";
                                                                          ^^^^^^^^
SyntaxError: Named export 'Database' not found. The requested module 'infrastructure' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'infrastructure';
const { StudentRepository, TeacherRepository, LoggerImpl, DatabaseTypes, Database } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:181:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:264:5)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:583:26)
    at async formattedImport (/usr/src/Node.JSRestAPI/node_modules/mocha/lib/nodejs/esm-utils.js:9:14)
    at async Object.exports.requireOrImport (/usr/src/Node.JSRestAPI/node_modules/mocha/lib/nodejs/esm-utils.js:42:28)
    at async Object.exports.loadFilesAsync (/usr/src/Node.JSRestAPI/node_modules/mocha/lib/nodejs/esm-utils.js:100:20)
    at async singleRun (/usr/src/Node.JSRestAPI/node_modules/mocha/lib/cli/run-helpers.js:162:3)
    at async Object.exports.handler (/usr/src/Node.JSRestAPI/node_modules/mocha/lib/cli/run.js:375:5)

@danielpza
Copy link

@jakebailey
Copy link

TS 5.9 will have node20 resolution, if you're willing to wait for that.

@danielpza
Copy link

I'm not seeing objections to adjust the node 20/22 bases (other than there's no node20/node22 module option (yet)). @jakebailey would you accept a PR changing it to NodeNext for the node versions that support it?

@jakebailey
Copy link

I can't say I especially like suggesting nodenext given it's a moving target, but I guess these packages are a moving target too, so, I guess? I'm not the arbitor of these packages 😄

@danielpza danielpza linked a pull request Mar 19, 2025 that will close this issue
@danielpza
Copy link

Created a pull request, see #301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants