-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Permitted TypeScript moduleResolution field is silently ignored during build step #38854
Comments
I'm also running into this issue. I have my tsconfig's For instance: import * as M from "capi/frame_metadata";
// ... The following error occurs upon running
I'd also recommend that setting the tsconfig field auto-disable the |
Same. I'm also running into this problem.
And same error occurs upon running next build. Seems like quite a big problem that type resolution of |
Please verify that your issue can be recreated with Why was this issue marked with the
|
hey @jankaifer, i've verified that this is still a problem with the latest canary. new sandbox: https://stackblitz.com/edit/vercel-next-js-cpvefa repro steps:
|
I have spun up a new PR that aims to resolve this issue: #45670 |
#45670) ## Bug The `next build` command is silently overriding the user's tsconfig when it shouldn't be; this results in mismatched behavior between `tsc --noEmit` and `yarn build` and user confusion. For example, a configuration option like `"moduleResolution": "nodenext"`, which is preserved and respected by `next dev`, will be silently overridden to `"moduleResolution": "node"` during `next build`. This change: - Fixes #38854 - (probably fixes) #45452 (I have not verified) - (probably fixes) #41189 (I have not verified) ## Details Next has a concept of both _defaults_ and _permitted options_ when modifying/validating the user's tsconfig. The user's config is only modified if it does not match the _permitted options_. This means that if the user has specified a permitted value like `"moduleResolution": "nodenext"`, it will not be overwritten in the user's config file. However, there was some logic in `runTypeCheck.ts` that did not adequately capture this nuance – instead, it spread all of the defaults into the tsconfig it was building before running typecheck, which meant that if a user had specified an option that was _permitted_ but _non-default_, it would be overwritten, silently, during `yarn build` only. Because Next is already (1) rewriting the TSconfig in `writeConfigurationDefaults` when the user's config doesn't line up with what we're expecting and (2) verifying the user's TSConfig remains correct (in `verifyTypeScriptSetup`) during a `next build`, I believe that it is safe to remove this config-steamrolling behavior. ## Documentation / Examples I believe this is strictly a bugfix; it updates the behavior of `next build` to conform to the same configuration behavior exhibited by `tsc --noEmit` and `next dev`. Since this is already the user expectation, it should not require documentation changes. --------- Co-authored-by: Shu Ding <g@shud.in> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: Ubuntu 20.04.0 LTS Wed Jul 20 2022 15:07:23 GMT-0700 (Pacific Daylight Time)
Binaries:
Node: 16.14.2
npm: 7.17.0
Yarn: 1.22.10
pnpm: N/A
Relevant packages:
next: 12.2.3-canary.14
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
warn - Latest canary version not detected, detected: "12.2.3-canary.14", newest: "12.2.3-canary.15".
Please try the latest canary version (
npm install next@canary
) to confirm the issue still exists before creating a new issue.Read more - https://nextjs.org/docs/messages/opening-an-issue
NOTE: I was unable to install 12.2.3-canary.15, it doesn't seem to exist on NPM at the time of creating this issue
What browser are you using? (if relevant)
N/A
How are you deploying your application? (if relevant)
N/A
Describe the Bug
Running
next build
ignores themoduleResolution
field if it contains a value other thannodejs
, even when using a permitted type as outlined here:next.js/packages/next/lib/typescript/writeConfigurationDefaults.ts
Lines 59 to 61 in d895a50
This means that builds that pass direct type checking via
tsc
will fail to build ifnode12
ornodenext
are used.I did a bit of digging and it appears this is because while writeConfigurationDefaults allows
parsedValues
options above,getRequiredConfiguration
only returnsparsedValue
and which overrides the user's config:next.js/packages/next/lib/typescript/runTypeCheck.ts
Lines 39 to 47 in 0d80b11
If this is not the expected behavior I'm happy to attempt a PR to fix, but wanted to confirm before giving it a shot.
Expected Behavior
Running
yarn build
should respect themoduleResolution
field when it contains a permitted value other thannodejs
.Link to reproduction
https://stackblitz.com/edit/vercel-next-js-wtfonr
To Reproduce
Run
yarn build
(and also observe thatyarn tsc
does not error)The text was updated successfully, but these errors were encountered: