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

Allow options.configFile to be undefined #1345

Closed
mjbvz opened this issue Jul 23, 2021 · 4 comments · Fixed by #1346
Closed

Allow options.configFile to be undefined #1345

mjbvz opened this issue Jul 23, 2021 · 4 comments · Fixed by #1346

Comments

@mjbvz
Copy link

mjbvz commented Jul 23, 2021

Expected Behaviour

options.configFile should allow passing in undefined to fallback the standard config file

We hit this with a webpack config generator function that looks like:

function createWebpackConfig(configFileName: string | undefined) {
 ...
}

Sometimes we want to override the config file but usually we do not

Actual Behaviour

Passing in undefined produces the following build error:

Module build failed (from ./node_modules/ts-loader/index.js):
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:124:11)
    at Object.isAbsolute (path.js:1133:5)
    at findConfigFile (/workspaces/ts-loader/examples/vanilla/node_modules/ts-loader/dist/config.js:57:14)
    at Object.getConfigFile (/workspaces/ts-loader/examples/vanilla/node_modules/ts-loader/dist/config.js:8:28)
    at successfulTypeScriptInstance (/workspaces/ts-loader/examples/vanilla/node_modules/ts-loader/dist/instances.js:74:40)
    at Object.getTypeScriptInstance (/workspaces/ts-loader/examples/vanilla/node_modules/ts-loader/dist/instances.js:42:12)
    at Object.loader (/workspaces/ts-loader/examples/vanilla/node_modules/ts-loader/dist/index.js:16:41)

Again, I'd expect undefined to be treated as if the configFile property has been omitted entirely

Steps to Reproduce the Problem

  1. In examples/vanilla, update the rules to:
rules: [
    {
        test: /\.tsx?$/,
        loader: 'ts-loader',
        options: {
            configFile: undefined
        }
    }
]
  1. Now build: yarn run build

Location of a Minimal Repository that Demonstrates the Issue.

Apply this diff in this repo:

diff --git a/examples/vanilla/webpack.config.js b/examples/vanilla/webpack.config.js
index 32e454fe..ae9fb98d 100644
--- a/examples/vanilla/webpack.config.js
+++ b/examples/vanilla/webpack.config.js
@@ -13,7 +13,10 @@ module.exports = {
         rules: [
             {
                 test: /\.tsx?$/,
-                loader: 'ts-loader'
+                loader: 'ts-loader',
+                options: {
+                    configFile: undefined
+                }
             }
         ]
     },
@johnnyreilly
Copy link
Member

Thanks for this. I'm on a train and slightly tipsy, but on the face of it I think you're probably right. Ideally I'd expect undefined to be treated as if the configFile property has been omitted entirely.

Feels like it's probably an easy fix. If you'd like to submit a PR I'll happily review it. Failing that I'll likely take a look at some point.

@johnnyreilly
Copy link
Member

johnnyreilly commented Jul 24, 2021

Prospective fix PR is up - just waiting for GitHub Actions to get happy again; there seem to be some issues.

@johnnyreilly
Copy link
Member

And apropos of nothing, amazing work on https://code2020.dev/ - it's a gift to the community! ❤️ 🌻

@johnnyreilly
Copy link
Member

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.

2 participants