tiktok / rush-plugins

MIT License
17 stars 2 forks source link

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

Closed MichaelSitter closed 2 months ago

MichaelSitter commented 11 months ago

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 commented 11 months ago

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.

/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: https://github.com/TypeStrong/ts-node/issues/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 commented 11 months ago

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

MichaelSitter commented 10 months ago

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

octogonz commented 10 months ago

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