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

rush-init-project-plugin fails for typescript init.config files #7

Open
MichaelSitter opened this issue Oct 29, 2023 · 4 comments
Open

Comments

@MichaelSitter
Copy link

If you use the documented setup for init.config.ts, the plugins internal ts-node build fails with the following error:

Starting "rush init-project"

? Please select a template node-lib
Hello from template configuration! "node-lib" /Users/michaelsitter/dev/web-projects/common/_templates/node-lib
⨯ Unable to compile TypeScript:
error TS5109: Option 'moduleResolution' must be set to 'Node16' (or left unspecified) when option 'module' is set to 'Node16'.

I think I managed to track the failure down to this line in TemplateConfiguration. I experimentally added module: 'none' & it resolves this issue, but it's not clear to me what should actually be happening here. Is ts-node supposed to be discovering a tsconfig file at this step, or is this intentionally hardcoded in the plugin?

I have a branch which reproduces this issue here: https://github.com/MichaelSitter/web-projects/tree/rush-init-project-ts-config-repro

@chengcyber
Copy link
Member

chengcyber commented Oct 30, 2023

Hi Michael! Thanks for reporting this to us and the useful reproduce repository looks great to me!

I can see you are using Node.js 20 in your repository, the temporary workaround is adding a tsconfig.json file in your monorepo root.

<monorepo_root>/tsconfig.json

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "display": "Node 20",
  "_version": "20.1.0",

  "compilerOptions": {
    "lib": ["es2023"],
    "module": "node16",
    "target": "es2022",

    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node16"
  }
}

Details

I would like to elaborate a little bit more if you are interested. Your investigation on the TemplateConfiguration is right. The problem is the latest stable version of ts-node has not supported Node.js > 16 yet. So it might not work well with the latest Node.js version.

Fortunately, ts-node is working on this! There is a new beta version of ts-node@11. With this beta version, ts-node can work well with Node.js 18 and 20. Ref: TypeStrong/ts-node#2077

I will release a new version of the rush-init-project-plugin after the ts-node@11 was released as stable version.

The temporary workaround is adding a tsconfig.json manually under the root of monorepo. That makes the ts-node gets the correct tsconfig.json for Node.js 20.

The content of this tsconfig.json comes from @tsconfig/node20.

@chengcyber
Copy link
Member

Update: rush-init-project-plugin@0.10.0-beta.0 has been released. It uses ts-node@11 beta version.

@MichaelSitter
Copy link
Author

thanks @chengcyber!!! i'll pull it in & test it on my side.

@octogonz
Copy link
Member

octogonz commented Dec 6, 2023

@MichaelSitter if the problem is resolved, should we close this issue?

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

No branches or pull requests

3 participants