Skip to content

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

Closed
@Jamesernator

Description

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
  }
}

Metadata

Assignees

No one assigned

    Labels

    you can do thisGood candidate for a pull request.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions