Skip to content

Can ts-node work with standard-things/esm? #424

@seangwright

Description

@seangwright

I realize ts-node does not support ES modules because node does not (yet), so I would like to use esm as the compat layer for using ES modules in node.
https://github.com/standard-things/esm

main.ts

require = require('@std/esm')(module, { cjs: true, esm: 'js' });

const PI = require('./test').default;

console.log(PI);

test.ts

const PI = 3.14;

export default PI;

tsconfig.json

{
    "compilerOptions": {
        "module": "es2015",
        "moduleResolution": "node",
        "target": "es2015",
        "allowJs": true,
        "lib": [
            "es2017",
            "dom"
        ],
    }
}

I'm running ts-node -P ./tsconfig.json ./main.ts

Error

..\app\node_modules\source-map-support\source-map-support.js:372
  return error + stack.map(function(frame) {
               ^

TypeError: Cannot convert object to primitive value
    at Function.prepareStackTrace (..\app\node_modules\source-map-support\source-map-support.js:372:16)
    at process.emit (..\app\node_modules\source-map-support\source-map-support.js:422:51)
    at process._fatalException (bootstrap_node.js:332:26)

The paths in the error above were truncated by me - they were printed as absolute filesystem paths.

When I compile this code using tsc -p ./tsconfig.json I can then run $ node main.js with an output of 3.14, so I feel the issue is how I'm using ts-node or limitations in the package.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions