I have a yarn ts monorepo, it has these subdirectories core server tests here is my root…
- User
I have a yarn ts monorepo, it has these subdirectories core server tests here is my root tsconfig { "compilerOptions": { "target": "es2020", "module": "commonjs", "moduleResolution": "node", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, "baseUrl": ".", "paths": { "@photon/core/": ["core/src/"], "@photon/server/": ["server/src/"] }, "outDir": "dist", "sourceMap": true, "inlineSources": true, "rootDir": ".", "declaration": true, "composite": true, "skipLibCheck": true }, "references": [ { "path": "./core" }, { "path": "./server" }, { "path": "./tests" } ] } and here is tsconfig for core { "extends": "../tsconfig.json", "compilerOptions": { "outDir": "./dist", "rootDir": "./src", "sourceMap": true }, "include": ["src//*"] } and tests { "extends": "../tsconfig.json", "compilerOptions": { "outDir": "./dist", "rootDir": "./src", "composite": true, "types": ["mocha", "chai"], "sourceMap": true }, "include": ["src//*"], "ts-node": { "transpileOnly": true, "files": true } }
the test script won't work, probably because I switched to commonjs
"test": "NODE_OPTIONS='--loader ts-node/esm' mocha --extensions ts \"src/**/*.test.ts\"",fix the test script
- Assistant
You're using
"module": "commonjs"in yourtsconfig.jsonfiles, but your test script is still using--loader ts-node/esmwhich is for ESM module support. Since your project compiles to CommonJS, you should avoid using the ESM loader and instead use the standard ts-node register loader for CommonJS.Fix to your
testscript:"test": "mocha --require ts-node/register --extensions ts \"src/**/*.test.ts\""Explanation
--loader ts-node/esmis for ESM modules, but you are targeting CommonJS.--require ts-node/registerworks with CommonJS to transpile on the fly with ts-node.- Mocha will pick up
.tsfiles and compile them using ts-node during tests. - Make sure
ts-node,mocha, and typings like@types/mochaand@types/chaiare installed.