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

[Node 17.5.0] JSON support in ESM no longer requires --experimental-json-modules #1661

Closed
Jamesernator opened this issue Feb 23, 2022 · 4 comments · Fixed by #1665
Closed
Labels
you can do this Good candidate for a pull request.
Milestone

Comments

@Jamesernator
Copy link
Contributor

Jamesernator commented Feb 23, 2022

Search Terms

json, json modules, esm, experimental-json-modules

Expected Behavior

To be able to import json modules without the --experimental-json-modules flag in ts-node/esm.

As of Node 17.5.0 the flag is no longer required, it just prints a usual experimental warning.

Actual Behavior

Currently ts-node/esm loader only allows JSON modules if --experimental-json-modules is passed to the Node executable. If this option is not passed it fails with an error despite Node no longer requiring the flag.

Steps to reproduce the problem

Import a json module and use node --loader ts-node/esm ./jsWithJsonImport.js.

The exact line that checks the condition is here. Simply removing the conditional would make the behaviour be consistent with node.

Specifications

ts-node v10.5.0
node v17.5.0
compiler v4.5.5
{
  "include": [
    "**/*.ts",
    "**/*.json"
  ],
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "sourceMap": true,
    "downlevelIteration": true,
    "composite": true,

    "strict": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noEmit": true,

    "allowSyntheticDefaultImports": true,
    "useDefineForClassFields": true,
    "importsNotUsedAsValues": "error",
    "noUncheckedIndexedAccess": true
  },
  "ts-node": {
    "transpileOnly": true
  }
}
@cspotcode
Copy link
Collaborator

cspotcode commented Feb 23, 2022

Sounds like a straightforward change, can you send us a pull request? The next version is going to be published soon, we can include it.

Might be best to keep the conditional check on versions of node earlier than 17.5.0, so that we're consistent with whatever node version you're running.

@cspotcode cspotcode added the you can do this Good candidate for a pull request. label Feb 23, 2022
@cspotcode cspotcode added this to the 10.6.0 or 10.5.1 milestone Feb 23, 2022
@cspotcode
Copy link
Collaborator

I've scheduled the 10.6.0 release for next Wednesday. If you're able to prepare a PR by then, we can include it in the release.

@cspotcode
Copy link
Collaborator

@Jamesernator is this something you can send a PR for? We can include it in 10.6.0 which I'd like to release tomorrow. My time is occupied by other tickets.

@Jamesernator
Copy link
Contributor Author

@Jamesernator is this something you can send a PR for? We can include it in 10.6.0 which I'd like to release tomorrow. My time is occupied by other tickets.

I've made the change on a fork, I just need to add a couple tests which I'll do sometime today.

@cspotcode cspotcode modified the milestones: 10.6.0, 10.7.0 Mar 1, 2022
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this issue Mar 8, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [ts-node](https://typestrong.org/ts-node) ([source](https://github.com/TypeStrong/ts-node)) | devDependencies | minor | [`10.6.0` -> `10.7.0`](https://renovatebot.com/diffs/npm/ts-node/10.6.0/10.7.0) |

---

### Release Notes

<details>
<summary>TypeStrong/ts-node</summary>

### [`v10.7.0`](https://github.com/TypeStrong/ts-node/releases/v10.7.0)

[Compare Source](TypeStrong/ts-node@v10.6.0...v10.7.0)

Questions about this release? Ask in the official discussion thread: [#&#8203;1680](TypeStrong/ts-node#1680)

**Added**

-   Adds `--esm` flag, option, and `ts-node-esm` binary ([#&#8203;1258](TypeStrong/ts-node#1258), [#&#8203;1655](TypeStrong/ts-node#1655))
    -   Enables full `esm` support; no need for `--loader` nor `NODE_OPTIONS`
    -   Use shebang `#!/usr/bin/env ts-node-esm`, run `ts-node --esm`, or add to your tsconfig.json: `"ts-node": {"esm": true}`

**Changed**

-   Unflag ESM json modules on node >=17.5.0 ([#&#8203;1661](TypeStrong/ts-node#1661), [#&#8203;1665](TypeStrong/ts-node#1665)) [@&#8203;Jamesernator](https://github.com/Jamesernator)
    -   no longer requires `--experimental-json-modules`
-   Lazy-load dependencies to improve startup responsiveness. ([#&#8203;1676](TypeStrong/ts-node#1676))

**Fixed**

-   Fixed bug where "compiler", "transpiler", and swc backend would not resolve relative to the tsconfig.json that declared them ([#&#8203;1662](TypeStrong/ts-node#1662), [#&#8203;1655](TypeStrong/ts-node#1655))
    -   Enables reusable tsconfig.json shared via node module to include necessary dependencies

https://github.com/TypeStrong/ts-node/milestone/11

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1200
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
you can do this Good candidate for a pull request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants