Just started getting this npm build error with 2.2.1, not a ton of other details I can find yet.
./node_modules/typescript/lib/typescript.js:89078
throw new Error("Could not find file: '" + fileName + "'.");
using it like this
loaders: [{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [['es2015'], 'stage-0', 'react'].concat(DEBUG ? ['react-hmre'] : []),
},
},
{
loader: 'ts-loader',
},
],
},
If I revert to 2.2.0, everything works fine.
Using Typescript 2.4.1, NPM 5.0.3 on macOs
That's strange... Our builds are passing. Do you have any more details?
Would you be able to test the build I created here?: https://github.com/johnnyreilly/ts-loader
It contains a speculative fix for your issue...
Hey John, sorry no go on that one. Just compiled it, dropped it in and am getting this:
/Users/ta/development/src/node_modules/ts-loader/node_modules/typescript/lib/typescript.js:89078
throw new Error("Could not find file: '" + fileName + "'.");
^
Error: Could not find file: '/Users/ta/development/src/resources/assets/js/app.js'.
at getValidSourceFile (/Users/ta/development/src/node_modules/ts-loader/node_modules/typescript/lib/typescript.js:89078:23)
at Object.getSyntacticDiagnostics (/Users/ta/development/src/node_modules/ts-loader/node_modules/typescript/lib/typescript.js:89291:52)
at /Users/ta/development/src/node_modules/ts-loader/dist/after-compile.js:91:38
at Array.forEach (native)
at provideErrorsToWebpack (/Users/ta/development/src/node_modules/ts-loader/dist/after-compile.js:90:10)
at Compiler.<anonymous> (/Users/ta/development/src/node_modules/ts-loader/dist/after-compile.js:21:9)
at next (/Users/ta/development/src/node_modules/webpack/node_modules/tapable/lib/Tapable.js:140:14)
at Compiler.<anonymous> (/Users/ta/development/src/node_modules/webpack/lib/CachePlugin.js:62:5)
at Compiler.applyPluginsAsyncSeries (/Users/ta/development/src/node_modules/webpack/node_modules/tapable/lib/Tapable.js:142:13)
at /Users/ta/development/src/node_modules/webpack/lib/Compiler.js:513:10
The only thing that pops out is Tapable.js, which I'm assuming is installed via another package, as I don't explicitly have it in my package.json
The npm log file has even less info than that.
Thanks for testing. I'll probably merge that anyway as it uses the compiler methods for file resolution rather than ts-loader's and so it gets us closer to like-like behaviour between tsc and ts-loader. (Always a goal.)
I'm drawing a bit of a blank on what might be causing this. Ts-loader doesn't directly depend on tapable. Kind of surprised ts-loader 2.2.0 is working with ts 2.4.1 anyway. ts-loader 2.2.1 was released to address a change that broke ts-loader that landed in TypeScript with 2.4.1... See https://github.com/TypeStrong/ts-loader/issues/565
with 2.2.2 my project now compiles fine with TS 2.4.1 馃憤
Edit: Disregard, I had locked in my package.json at 2.2.0 and assumed npm update had updated it. 2.2.2 is still borked for me.
Been there, done that! I wonder what the issue can be... Can you share a repo that demo's the issue?
I encountered the same problem as @timothyallan. I'm on typescript 2.4.1. ts-loader 2.2.2 gives me the "could not find file" error and 2.2.0 gives me the error in https://github.com/TypeStrong/ts-loader/issues/565. Can someone re-open this issue?
Sure - we're unable to reproduce the issue though
I encountered this error with a single index.js file and the configuration below. Renaming the file to be index.ts did resolve the issue.
tsconfig:
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"sourceMap": true,
"jsx": "react",
"moduleResolution": "node",
"allowJs": true,
"checkJs": true
},
"include": [
"./results_page/client/**/*"
]
}
webpack.config.js
const path = require('path')
const webpack = require('webpack')
module.exports = {
context: __dirname,
entry: {
results_page: './results_page/client/index'
},
output: {
path: path.resolve('./static/bundles/'),
filename: '[name]-[hash].js',
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'ts-loader'
}
]
},
resolve: {
extensions: ['.js', '.jsx']
}
}
error:
ts-loader: Using [email protected] and /Users/frank/work/pollresults/tsconfig.json
/Users/frank/work/node_modules/typescript/lib/typescript.js:86054
throw new Error("Could not find file: '" + fileName + "'.");
^
Error: Could not find file: '/Users/frank/work/pollresults/results_page/client/index.js'.
at getValidSourceFile (/Users/frank/work/node_modules/typescript/lib/typescript.js:86054:23)
at Object.getSyntacticDiagnostics (/Users/frank/work/node_modules/typescript/lib/typescript.js:86258:52)
at /Users/frank/work/pollresults/node_modules/ts-loader/dist/after-compile.js:91:38
Nice find @frankwallis . The loader now passes my first app.js file when I rename it to app.ts. However, I'm using a very mixed .js/.jsx project, so there's a few .js files that I can't change to .ts i.e.
Error: Could not find file: '/Users/development/src/resources/assets/js/components/bootstrap.js'.
Is this related to https://github.com/TypeStrong/ts-loader/issues/586 by any chance?
ok after reading through #586 I managed to resolve it by adding the entryFileIsJs flag to the options:
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'ts-loader',
options: {
entryFileIsJs: true
}
}
]
},
It seems to me that specifying checkJs: true in tsconfig.json should perhaps have the same effect as specifying the entryFileIsJs flag?
The issue now is that it is type-checking js files in node_modules, which is the same issue as https://github.com/TypeStrong/ts-loader/issues/577.
It seems to me that specifying checkJs: true in tsconfig.json should perhaps have the same effect as specifying the entryFileIsJs flag?
Something worth considering. I mean to take another look at entryFileIsJs functionality.
The issue now is that it is type-checking js files in node_modules, which is the same issue as #577.
There was a potential solution to #577 - I was hoping for a PR on that. If you'd like to have a go you're most welcome!
See #586 for details of progress on this.
I believe this is now resolved by #590
Negatory :(
Erased node_modules, fresh npm install with 2.3.2
/Users/dev/web/src/node_modules/typescript/lib/typescript.js:89078
throw new Error("Could not find file: '" + fileName + "'.");
^
Error: Could not find file: '/Users/dev/web/src/resources/assets/js/app.js'.
at getValidSourceFile (/Users/dev/web/src/node_modules/typescript/lib/typescript.js:89078:23)
at Object.getSyntacticDiagnostics (/Users/dev/web/src/node_modules/typescript/lib/typescript.js:89291:52)
at /Users/dev/web/src/node_modules/ts-loader/dist/after-compile.js:93:38
at Array.forEach (native)
at provideErrorsToWebpack (/Users/dev/web/src/node_modules/ts-loader/dist/after-compile.js:92:10)
at Compiler.<anonymous> (/Users/dev/web/src/node_modules/ts-loader/dist/after-compile.js:22:9)
at next (/Users/dev/web/src/node_modules/webpack/node_modules/tapable/lib/Tapable.js:186:14)
at Compiler.<anonymous> (/Users/dev/web/src/node_modules/webpack/lib/CachePlugin.js:62:5)
at Compiler.applyPluginsAsyncSeries (/Users/dev/web/src/node_modules/webpack/node_modules/tapable/lib/Tapable.js:188:13)
at compilation.seal.err (/Users/dev/web/src/node_modules/webpack/lib/Compiler.js:517:11)
Rolling back to 2.2.0 still works great.
Could you provide a minimal repro please? I've got nothing to work with at present...
FWIW I'm pretty sure the @schmuli change is the cause: https://github.com/TypeStrong/ts-loader/pull/564/files
However without understanding what your use case is it's hard to know how to handle this correctly.
btw I'm kind of assuming you're usingcheckJs - can you confirm?
Totally understand on the min repro. This is a beast of a production project with a ton of linked stuff though. I'll see what I can do.
Relevant tsconfig below:
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"removeComments": true,
"noLib": false,
"jsx": "preserve",
"outDir": "dist",
"lib": ["dom", "esnext"],
"checkJs": true,
"allowJs": true,
"strictNullChecks": true,
"baseUrl": "./",
Thanks @timothyallan :+1:
@johnnyreilly I was also running into this error, and I fixed it by making sure that all expected files were included via the TSConfig file. This usually means having a "files" entry and optionally an "include" entry.
For example, in my situation I was trying to compile tests, using an entry file with a require.context call. It works when my tsconfig file looks like:
{
"compilerOptions": { ... },
"files": [ "main.spec.ts" ],
"includes": [
"./src/app/**/*.spec.ts",
"./src/app/**/*.spec.js"
]
}
Thanks @schmuli - hopefully with a minimal repro we can deal with this once and for all!
Sorry gents, calling this one a day. Amount of time spent debugging > amount of hassle switching to awesome-typescript-loader, which is working fine.
Most helpful comment
with 2.2.2 my project now compiles fine with TS 2.4.1 馃憤
Edit: Disregard, I had locked in my package.json at 2.2.0 and assumed
npm updatehad updated it. 2.2.2 is still borked for me.