Skip to content

typescript v2.1.4 doesn't like empty files in config #405

Closed

Description

@danfuzz

Line 49 of config.ts runs afoul of the tsconfig checker in v2.1.4 of the TypeScript compiler:

        configFile = {
            config: {
                compilerOptions: {},
                files: [], // <-------------- THIS LINE
            },
        };

https://github.com/TypeStrong/ts-loader/blob/master/src/config.ts#L49

In my project (https://github.com/danfuzz/quillex), I'm getting the error "error TS18002: The 'files' list in config file 'tsconfig.json' is empty." which I've tracked back to this. (Note: I currently work around this by pointing my project at an older version of typescript.)

If I add a dummy entry to the files list, then typescript stops complaining, and things seem to work as expected, e.g.:

        configFile = {
            config: {
                compilerOptions: {},
                files: ['i-really-hope-you-dont-have-a-file-with-this-name'],
            },
        };

I don't know if this is the best solution to the problem, nor if it causes some other problem that I just haven't noticed yet. For the record, totally removing the files binding causes a different error ("error TS18003: No inputs were found in config file 'tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '["node_modules","bower_components","jspm_packages"]'.").

typescript has an explicit error code and message for a specified-but-empty files list, so I'm guessing the change in behavior is intentional.

Activity

  1. danfuzz commented on Dec 8, 2016

    @danfuzz
    Author

    Here's the salient part of the stacktrace where the error is thrown:

        at getFileNames (.../node_modules/typescript/lib/typescript.js:64355:41)
        at Object.parseJsonConfigFileContent (.../node_modules/typescript/lib/typescript.js:64304:18)
        at Object.getConfigParseResult (.../node_modules/ts-loader/dist/config.js:70:38)
        at Object.ensureTypeScriptInstance (.../node_modules/ts-loader/dist/instances.js:33:36)
        at Object.loader (.../node_modules/ts-loader/dist/index.js:17:24)
    
  2. johnnyreilly commented on Dec 8, 2016

    @johnnyreilly
    Member

    Hi @danfuzz,

    Thanks for posting details of your workaround. That's interesting. That said; there's nothing really that we can usefully do about this - this is the behaviour of the TypeScript compiler as intended (and this is intended - raised an issue with team and had it confirmed)

  3. danfuzz commented on Dec 8, 2016

    @danfuzz
    Author

    I assume "nothing to do about this" doesn't actually mean that ts-loader will be left broken forever. Is my — admittedly gross — hack pretty much the best that can be done?

  4. johnnyreilly commented on Dec 8, 2016

    @johnnyreilly
    Member
  5. johnnyreilly commented on Dec 8, 2016

    @johnnyreilly
    Member

    Well you can stay on TypeScript 2.0 but yes that's pretty much it I'm afraid. Ts-loader works on top of TypeScript and we don't intend to implement different behaviour than the compiler for the most part

  6. johnnyreilly commented on Dec 8, 2016

    @johnnyreilly
    Member

    (not because we want to be difficult but that way pain lies - if not immediately then soon)

  7. danfuzz commented on Dec 8, 2016

    @danfuzz
    Author

    (Yeah I get that. I'm not interested in pegging the project to an old version of the compiler.)

    I think I'm confused, then. I don't think I'm using ts-loader in an unusual way; that is, I don't get what I'm doing that's different than other users of ts-loader. Like, what should I be doing differently if I want to use TS 2.1?

    FWIW, here's where I config ts-loader in my code: https://github.com/danfuzz/quillex/blob/master/server/ClientBundle.js#L93

  8. danfuzz commented on Dec 8, 2016

    @danfuzz
    Author

    In any case, thanks for the replies and the info.

  9. johnnyreilly commented on Dec 8, 2016

    @johnnyreilly
    Member

    No problem. For what it's worth it's totally normal to not specify files at all. See this example: https://github.com/johnnyreilly/proverb-signalr-react/blob/master/tsconfig.json

  10. danfuzz commented on Dec 8, 2016

    @danfuzz
    Author

    Just as a coda on this: I figured out what the salient difference is between my situation and other projects'. I'd be surprised if I'm the only one who runs into this, so if nothing else the following can serve as a heads-up.

    My project is using TS because it includes the module parchment https://github.com/quilljs/parchment, which is written in TS. Parchment is distributed via npm as a prebuilt JS bundle (built using Webpack) and also includes the original .ts files, but it doesn't include a tsconfig.json file in the npm package. I'm choosing to compile the .ts files (and not use the bundle) because I don't want to have a double layer of Webpack loaders (that is, I'm making my own unified bundle of all the client code). That's why I'm using ts-loader.

    So, what ts-loader is getting pointed at is a .ts file which doesn't have a tsconfig.json anywhere around it. This means the getConfigFile() call in ts-loader/config.ts ends up falling through and returning that default one with an empty files list. And it looks to me like any time that that happens, the subsequent attempt to run compilation will fail.

    What I can do to work around the problem is add a new tsconfig.json file as a peer to the node_modules directory where parchment lands. (I could also drop one in the parchment directory, but if I do that, I'd no longer be using a pristine package from the npm registry.)

  11. johnnyreilly commented on Dec 8, 2016

    @johnnyreilly
    Member

    FWIW - it's not advised to ship TS in node_modules - ts-loader actually warns about this now: #399

  12. danfuzz commented on Dec 8, 2016

    @danfuzz
    Author

    Huh, well that's a bummer too, because ideally I'd love to keep referring to parchment via npm and not have to e.g. pull in its git repo.

  13. danfuzz commented on Dec 8, 2016

    @danfuzz
    Author

    Actually it's even worse: I don't use parchment directly. I use it because it's a dependency of quill (which isn't written in TS). So, if I have to stop getting Parchment from npm I also have to stop getting Quill from npm (or hand-patch its dependencies somehow).

  14. danfuzz commented on Dec 8, 2016

    @danfuzz
    Author

    I'm saying the above by way of advocacy: I actively like the fact that Parchment gives me a choice of whether or not to use the TS source, while still using npm.

  15. 13 remaining items

  16. univerio commented on Jan 10, 2018

    @univerio
    Contributor

    I ran into the same, but in my case my tsconfig.json was in a different directory than the project root, so while a relative path doesn't work:

    {
      test: /\.tsx?$/,
      loader: "ts-loader",
      options: {
        configFile: "./foo/tsconfig.json"
      }
    }
    

    an absolute path works just fine:

    {
      test: /\.tsx?$/,
      loader: "ts-loader",
      options: {
        configFile: path.resolve(__dirname, "foo", "tsconfig.json")
      }
    }
    
  17. danfuzz commented on Jun 26, 2018

    @danfuzz
    Author

    BTW the underlying TS issue was just closed as "fixed," and looks like it will be released with TS 3.0: microsoft/TypeScript#12762 (comment)

  18. a-x- commented on May 15, 2020

    @a-x-

    I even had a typo in config file name.

    Please, make this error more informative!
    Really, what the files, if config file even does not exist.

  19. Volmarg commented on Jul 12, 2020

    @Volmarg

    So i had the same issue, but actually non of the solutions were working. Spent couple hours on fixing it.
    So my case:

    Symfony 4.4 + Webpack-encore

    1. Install ts-loader: npm install --save-dev ts-loader@3.5.0
    2. Create tsconfig.json in the same dir where webpack.config.js is. In my case root ./
    3. Add in webpack.config.js
    Encore
        <other stuff>
        .enableTypeScriptLoader(function (typeScriptConfigOptions) {
            typeScriptConfigOptions.transpileOnly = true;
            typeScriptConfigOptions.configFile    = 'tsconfig.json';
        })
    
    1. Add in tsconfig.js
    {
      "compilerOptions": {
        "target": "es5"
      },
      "include": [
        "src/assets/scripts/validators/forms.ts"
      ],
      "exclude": []
    }
    

    On the moment of writing this i only know how to include single files, there must be way to add scan of dir but for now it's ok`

    Tip

    • some ppl recommend to change the entry file to .ts, but .js is working also for me
    Encore
        .addEntry('app', './src/app.js')
    
  20. added a commit that references this issue on Jul 16, 2020
  21. newdaveespionage commented on Sep 9, 2020

    @newdaveespionage

    I've just stumbled into this error as well, and reason was actually quite different. I passed full path to configFileName property, but it actually takes a name of the file. ts-loader applies tsconfig search logic similar to tsc. Funny thing that it worked quite well on linux and mac, but failed on windows.

    Eons ago now, but this was the issue I encountered, difference being that I had in my webpack.config.js

                options: {
                  configFile: './tsconfig.build.json',
                },
    

    When what ts-loader wanted was

                options: {
                  configFile: 'tsconfig.build.json',
                },
    
  22. joshverd commented on Sep 16, 2020

    @joshverd

    I fixed this issue by adding __dirname before the config file's name:

            options: {
              configFile: __dirname + '/src/react.tsconfig.json',
            },
    
  23. lpender commented on Apr 8, 2021

    @lpender

    I ultimately solved this only by upgrading to webpack 5

  24. JeukHwang commented on Aug 7, 2022

    @JeukHwang

    In my case,
    webpack configuration file was in [project directory]/config/dist.webpack.cjs and
    typescript configuration file was in [project directory]/config/dist.tsconfig.json.
    The following code was working for me.

    {
                test: /\.tsx?$/,
                use: [{
                    loader: "ts-loader",
                    options: { configFile: "config/dist.tsconfig.json" },
                }],
                exclude: /node_modules/,
    }
    
  25. added a commit that references this issue on Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions