Repository navigation
Modules in tests? #64
Description
Activity
If I replace all the imports with
let … = require(…)thing, it crashes on the first requiredexportwith a SyntaxErrorNote that the tests do run with no problems if I call
npx ts-node src/tests/utils.tsThis project uses the
ts-node/esmloader internally, so it may cause issues with CommonJS:Line 27 in e6cfd84
const esmLoader = pathToFileURL(require.resolve('ts-node/esm')).toString() Can you try with
esModuleInteropset totruein tsconfig.json?You may also have this affect ts-node only, and not your build results: https://github.com/TypeStrong/ts-node/#via-tsconfigjson-recommended
Maybe related: nodejs/node#47880
Can you try with Node.js 18 just so we know whether the Node.js loaders issue is at the root of this problem?
Reacted by Kenichi KamiyaThis project uses the
ts-node/esmloader internally, so it may cause issues with CommonJS:Line 27 in e6cfd84
const esmLoader = pathToFileURL(require.resolve('ts-node/esm')).toString() Can you try with
esModuleInteropset totruein tsconfig.json?You may also have this affect ts-node only, and not your build results: TypeStrong/ts-node#via-tsconfigjson-recommended
"esModuleInterop": truedoesn't help. It still throwsSyntaxError: Cannot use import statement outside a module.
Tests do work if I have"type": "module"in mypackage.jsonbut then I cannot run my code as normal (TypeScript complains that.tsis not a valid file type??)I managed to make it run like normal with
"type": "module"by usingtsxmyself instead ofts-node
For some reason, I am unable to use modules in tests.
If I try to make the file
.mtsinstead of.ts, the error changes:while the
utils.(m)tsfile starts withNote that I am unable to change my
"module": "commonjs"intsconfig.jsonand I cannot put"type": "module"in mypackage.json. If I do any of those, it still doesn't work, and the rest of my project breaks as well.