Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.2.1 = npm error "Could not find file:" ... #568

Closed
timothyallan opened this issue Jun 29, 2017 · 24 comments · Fixed by xing/hops#996
Closed

2.2.1 = npm error "Could not find file:" ... #568

timothyallan opened this issue Jun 29, 2017 · 24 comments · Fixed by xing/hops#996

Comments

@timothyallan
Copy link

timothyallan commented Jun 29, 2017

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

@johnnyreilly
Copy link
Member

That's strange... Our builds are passing. Do you have any more details?

@johnnyreilly
Copy link
Member

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...

@timothyallan
Copy link
Author

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.

@johnnyreilly
Copy link
Member

johnnyreilly commented Jun 30, 2017

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 #565

johnnyreilly added a commit that referenced this issue Jul 1, 2017
* Speculative fix for #568

* Remove default of setting isolatedModules to true when in transpileOnly mode

Not useful for when using ts-loader with fork-ts-checker-webpack-plugin.  Can still be set manually with tsconfig.json if desired and so arguably not a breaking change
@timothyallan
Copy link
Author

timothyallan commented Jul 3, 2017

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.

@johnnyreilly
Copy link
Member

Been there, done that! I wonder what the issue can be... Can you share a repo that demo's the issue?

@huy-nguyen
Copy link

huy-nguyen commented Jul 3, 2017

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 #565. Can someone re-open this issue?

@johnnyreilly johnnyreilly reopened this Jul 3, 2017
@johnnyreilly
Copy link
Member

Sure - we're unable to reproduce the issue though

@frankwallis
Copy link

frankwallis commented Jul 25, 2017

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 typescript@2.3.4 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

@timothyallan
Copy link
Author

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'.

@johnnyreilly
Copy link
Member

Is this related to #586 by any chance?

@frankwallis
Copy link

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 #577.

@johnnyreilly
Copy link
Member

johnnyreilly commented Jul 26, 2017

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!

@johnnyreilly
Copy link
Member

johnnyreilly commented Jul 26, 2017

See #586 for details of progress on this.

@johnnyreilly
Copy link
Member

I believe this is now resolved by #590

@timothyallan
Copy link
Author

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.

@johnnyreilly johnnyreilly reopened this Jul 27, 2017
@johnnyreilly
Copy link
Member

Could you provide a minimal repro please? I've got nothing to work with at present...

@johnnyreilly
Copy link
Member

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.

@johnnyreilly
Copy link
Member

btw I'm kind of assuming you're usingcheckJs - can you confirm?

@timothyallan
Copy link
Author

timothyallan commented Jul 27, 2017

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": "./",

@johnnyreilly
Copy link
Member

Thanks @timothyallan 👍

@schmuli
Copy link
Contributor

schmuli commented Jul 27, 2017

@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"
    ]
}

@johnnyreilly
Copy link
Member

Thanks @schmuli - hopefully with a minimal repro we can deal with this once and for all!

@timothyallan
Copy link
Author

Sorry gents, calling this one a day. Amount of time spent debugging > amount of hassle switching to awesome-typescript-loader, which is working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants