-
Notifications
You must be signed in to change notification settings - Fork 2k
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 module: "CommonJS", moduleResolution: "nodeNext"
doesn't work (but we're not sure if it's supposed to)
#7222
Comments
We do literally have a smoke test for this as part of our CI ( |
So, we test with these set:
If I set (If I only set Is |
I've tried a few times previously to move to type: module in the package.json but that makes everything pretty horrible and leaves too many things to fix. So, don't want to make that change. Renaming the file to .mts might be an option. I'll need to try that. Though, I'm not sure what sort of effects that will have. I started with module CommonJS because that seems to be recommended for node serverside packages. I'm using npm packages to split code up and kept having to mess with the package imports when the moduleResolution was Node. I switched it to NodeNext and the package imports started working like I would expect. So that is how I got to both of those two settings. Example of previous package import: '@packagename/src/some-object'. Then I would have to delete '/src' from the import. Edit: these package imports are being auto included is VSCode. I'll add some sort of reference in the code, VSCode will suggest an import, and taking the default either gives me an import I need to edit, or it gives me the correct import with NodeNext. |
FWIW I saw something about this in at least one place in the TypeScript docs that strikes me as outdated (ie, not updated after TS4.7 with the new nodenext options). (In general the TS docs are excellent in that any given piece of text is well-written, but so much recent functionality is largely only documented in their (excellent) release notes posts...) Anyway I think we are happy to accept changes to try to improve this combination of options but figuring it out ourselves on the core team is probably not going to be a priority, given how every time we try to improve anything relating to the module system it ends up being a huge wild goose chase... |
Ok, I appreciate you taking a look. Do you want me to close this or keep it open? I'm new to the module system so have no idea how to help at the moment. |
module: "CommonJS", moduleResolution: "nodeNext"
doesn't work (but we're not sure if it's supposed to)
We can leave it open; I updated the title |
You can fix this by providing a separate .d.cts type export under the exports field https://www.typescriptlang.org/docs/handbook/esm-node.html#packagejson-exports-imports-and-self-referencing |
@jfrconley thanks for some insight! The whole typescript + cjs/esm situation is rough. I won't be able to address the issue myself in any meaningful timeframe, but I'd welcome a PR that did if you'd like to take that on? |
Also check out https://arethetypeswrong.github.io/?p=%40apollo%2Fserver%404.7.1, which shows this issue |
@benasher44 neat, thanks for that. We have a script that explicitly removes types from the |
@trevor-scheer Yes! @andrewbranch did a great job walking through all the edges in a different project's issue, starting from this issue comment |
I took a stab at fixing the typings straight in the repo here. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue Description
When the tsconfig moduleresolution is set to "nodenext", the @apollo/server can't be imported because: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'.
But, changing the moduleresolution to "node" will make the import work.
Is this an issue with Apollo Server?
Link to Reproduction
https://github.com/CaseyHaralson/apolloserver-bug-7222
Reproduction Steps
npm install
npm run build
Then change the moduleresolution type and run the build again.
Edit: updated repo link to include bug number
The text was updated successfully, but these errors were encountered: