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!
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
test.ts
tsconfig.json
I'm running
ts-node -P ./tsconfig.json ./main.tsError
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.jsonI can then run$ node main.jswith an output of3.14, so I feel the issue is how I'm usingts-nodeor limitations in the package.Thanks!