Something that changed between ts-node 6.1.0 and 7.0.0 broke a previously working project (or revealed a long-standing bug in my code).
In app/server/index.ts I have:
import * as next from 'next'
types for which are defined - as far as I can tell, correctly - in a local, hand-crafted d.ts file in /app/@types/.
tsconfig.server.json is:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"jsx": "react",
"outDir": "dist/"
},
"include": ["app/server/**/*.ts", "./app/@types/**/*.ts"]
}
which extends tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"jsx": "preserve",
"lib": ["dom", "es2016"],
"module": "esnext",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"preserveConstEnums": true,
"removeComments": false,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "esnext",
"typeRoots": ["./node_modules/@types", "./lib/@types", "./app/@types"]
}
}
under ts-node 6.1.0, the application starts as expected. Under ts-node 7.0.0, I get the following error:
TSError: ⨯ Unable to compile TypeScript:
app/server/index.ts(6,23): error TS7016: Could not find a declaration file for module 'next'. '/usr/src/service/node_modules/next/dist/server/next.js' implicitly has an 'any' type.
Were there significant behaviour changes between 6.1.0 and 7.0.0, or did something get stricter? I can't see a changelog anywhere. I _suspect_ it might be due to some error in the declarations file, but I can't see one.
I'm having the same issue with a nearly identical setup to @majelbstoat.
The changes from 6.2.0 to 7.0.0 are here https://github.com/TypeStrong/ts-node/commit/33cb1b5faecaa652b70fe97cb3665de7d42565c2 and the changelog message reads
Skip loading
tsconfig.jsonfiles by default to speed up startup
Given this change, how are local/custom types intended to be referenced?
@mastermatt @majelbstoat putting my .d.ts files at the root of my project (with tsconfig.json and package.json) did the job for me.
That's helpful to know @lucasriondel, thanks. However, I also symlink in a directory of common types from elsewhere in a mono-repo, so i need to be able to specify a path to them.
Using the recently added --files flag solved this issue for me. (Note that the flag behavior was inverted after v7.0.0)
Please take a look at https://github.com/TypeStrong/ts-node/issues/615.
for gulp users, add process.env['TS_NODE_FILES'] = true is to enable loading files from tsconfig.json.
gulp.task('test', function() {
let target = 'test/*.spec.ts'
process.env['TS_NODE_FILES'] = true
return gulp
.src([target], { read: false })
.pipe(
mocha({
reporter: 'list',
require: ['ts-node/register'],
timeout: '120000'
})
)
.on('error', gutil.log)
})
Using the recently added
--filesflag solved this issue for me. (Note that the flag behavior was inverted after v7.0.0)
Thank you so much. it worked! I thought the problem was the typescript compiler
Most helpful comment
for gulp users, add
process.env['TS_NODE_FILES'] = trueis to enable loading files from tsconfig.json.