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

verbatimModuleSyntax w/transpileOnly raises diagnostic error #1971

Closed
Jamesernator opened this issue Mar 17, 2023 · 4 comments · Fixed by #1973
Closed

verbatimModuleSyntax w/transpileOnly raises diagnostic error #1971

Jamesernator opened this issue Mar 17, 2023 · 4 comments · Fixed by #1973

Comments

@Jamesernator
Copy link
Contributor

Search Terms

isolatedModules, verbatimModuleSyntax

Expected Behavior

Ts-node should work with verbatimModuleSyntax: true.

Actual Behavior

With the new config flag, ts-node fails to load any TS files with the following error:

/home/jamesernator/projects/playground/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
error TS5104: Option 'isolatedModules' is redundant and cannot be specified with option 'verbatimModuleSyntax'.

    at createTSError (/home/jamesernator/projects/playground/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/home/jamesernator/projects/playground/node_modules/ts-node/src/index.ts:863:19)
    at /home/jamesernator/projects/playground/node_modules/ts-node/src/index.ts:1379:34
    at Object.compile (/home/jamesernator/projects/playground/node_modules/ts-node/src/index.ts:1453:13)
    at transformSource (/home/jamesernator/projects/playground/node_modules/ts-node/src/esm.ts:400:37)
    at /home/jamesernator/projects/playground/node_modules/ts-node/src/esm.ts:278:53
    at async addShortCircuitFlag (/home/jamesernator/projects/playground/node_modules/ts-node/src/esm.ts:409:15)
    at async nextLoad (node:internal/modules/esm/loader:163:22)
    at async ESMLoader.load (node:internal/modules/esm/loader:597:20)
    at async ESMLoader.moduleProvider (node:internal/modules/esm/loader:449:11) {
  diagnosticCodes: [ 5104 ]
}

Steps to reproduce the problem

Run node --loader ts-node/esm ./test.ts (where test.ts) is any ts file when verbatimModuleSyntax: true is set.

Minimal reproduction

https://gist.github.com/Jamesernator/5c4598178a4f4c3ce6961aa052a48d2a

Specifications

*ts-node v10.9.1

  • node v19.7.0
  • compiler v5.0.2
  • tsconfig.json, if you're using one:
{
    "include": [
        "./**/*.ts",
        "./**/*.mts",
        "./**/*.cts",
        "./**/*.json"
    ],
    "exclude": [
        "./**/*.d.ts",
        "./**/*.d.mts",
        "./**/*.d.cts"
    ],
    "compilerOptions": {
        "resolveJsonModule": true,
        "composite": true,
        "declaration": true,
        "declarationMap": true,
        "downlevelIteration": true,
        "module": "NodeNext",
        "moduleResolution": "nodenext",
        "rootDir": "./",
        "sourceMap": true,
        "target": "ES2022",
        "newLine": "lf",
        "useDefineForClassFields": true,
        "strict": true,
        "alwaysStrict": true,
        "exactOptionalPropertyTypes": true,
        "noImplicitOverride": true,
        "noUncheckedIndexedAccess": true,
        "forceConsistentCasingInFileNames": true,
        "verbatimModuleSyntax": true
    },
    "ts-node": {
        "transpileOnly": true   
    }
}
  • package.json
{
    "type": "module",
    "dependencies": {
        "ts-node": "^10.9.1",
        "typescript": "^5.0.2"  
    }
}
@Mister-Hope
Copy link

I think ts-node does not add support for typescript v5 right now, so I think maybe this should be a feature request supporting typescript v5.

@connorjs
Copy link

Do we want to rename this to the general TypeScript 5 support issue, then? Or would we prefer another?

@cspotcode
Copy link
Collaborator

Some TS 5.0 stuff has already merged, such as #1958. It still needs to be published, but in the meantime, enterprising users can install ts-node directly from git.

Our nightly automated tests also run against TS 5.0, so most things already work.

This looks specifically like an issue with transpileOnly, probably a very small code change to support it. We can detect when verbatimModuleSyntax is true, and remove isolatedModules from the config in those cases. Unless this config is happening within the TypeScript compiler's transpileModule function, in which case it would be a bug report for the TypeScript team.

Is anyone able to test some short-term workarounds? Short-term workarounds are not mutually exclusive with making the necessary code changes and publishing a new version of ts-node.

Here is a workaround that I have not had time to test, please let us know if it works for you:

Workaround: add 5104 to ignored diagnostic codes

https://typestrong.org/ts-node/docs/options#ignorediagnostics

Can go in tsconfig.json:

  "ts-node": {
    "ignoreDiagnostics": [5104]
  }

@cspotcode
Copy link
Collaborator

cspotcode commented Mar 17, 2023

Notes for getting a fix implemented in ts-node

We ship our own version of TS's transpileModule, which was introduced here: https://github.com/TypeStrong/ts-node/pull/1694/files#diff-5a3f7d2f06b8ba333a65357acad2413fbaff8ed768c2a5f297f0e0f565083962

This will need to be synced up with recent updates to transpileModule in the TS codebase: https://github.com/microsoft/TypeScript/blob/f473058361474507b03726b1ac9cd280c9580091/src/services/transpile.ts#L46-L50

At the time that PR was written, transpileModule looked like this in the TS codebase. Our implementation is copied from it:
https://github.com/microsoft/TypeScript/blob/d1fa945261a30616c5e3557d1a9fc18f3482af30/src/services/transpile.ts

Our automated tests also test against older TS versions, so they'll flag any potential incompatibilities with the oldest version of TS that we support.

@cspotcode cspotcode changed the title [TS5.0] verbatimModuleSyntax causes ts-node to always error verbatimModuleSyntax w/transpileOnly raises diagnostic error Mar 18, 2023
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.

4 participants