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

Missing queryString for inline entries like data:text/javascript,console.log("demo") #12214

Closed
jantimon opened this issue Dec 16, 2020 · 4 comments · Fixed by #12225
Closed

Comments

@jantimon
Copy link
Contributor

Bug report

What is the current behavior?

module.exports = {
  entry: {
    main: 'data:text/javascript,console.log("hello world");'
 },
 module: { 
   rules: [{
       loader: 'raw-loader',
       resourceQuery: query => { 
         console.log({query}); // logs: { query: undefined }
         return false
       },
      }
 ]}
};

According to the typings query will always be a string

| ((value: string) => boolean)

However as you see with the minimal reproduction example it is undefined for data:text/javascript,console.log("demo")
Would it be possible to provide an empty string in those cases?

Other relevant information:
webpack version: 5.10.3

Connected issues: vuejs/vue-loader#1771 & jantimon/html-webpack-plugin#1527

@sokra
Copy link
Member

sokra commented Dec 16, 2020

Yes, that's inconsistent between behavior and typings.

I would like to keep it undefined, because of 4 reasons:

  • It's makes more sense, as a Data URIs have no query string and "" would indicate an empty query string. So allowing to differ between "no query string" and "empty query string" is possible.
  • Changing the behavior would be a breaking change
  • When plugins add custom protocols, query is initialized to undefined too. So any other custom protocol would have the same behavior (if they don't explicitly support query string e. g. like http://)
  • There are probably many undefined or null related typings issues, as webpack itself is compiled in non-strict typescript mode.

So I'll update the typings and beg vue-loader to handle undefined...

@jantimon
Copy link
Contributor Author

I am happy with both ways :)

And @sodatea said he is okay with providing a fix on the vue-loader side vuejs/vue-loader#1771 (comment) 👍

Thanks for adjusting the types - should I close this one?

@jantimon jantimon reopened this Dec 17, 2020
@jantimon
Copy link
Contributor Author

@sokra I got directly the next bug report for the very same topic: jantimon/html-webpack-plugin#1527 (comment)

I guess most plugin/loader developer don't know about data:text/javascript,console.log("demo") and will not add unit tests and therefore have bugs in their current implementation..

Maybe it is good enough to update the typings and wait for all plugins to add support for inline scripts - but I guess it is really hard for users to understand why this error is happening as the error stack is quite had to read:

Click to expand error stack
Cannot read property 'startsWith' of undefined
Error: Child compilation failed:
  TypeError: Cannot read property 'startsWith' of undefined
  
  - RuleSetCompiler.js:220 Object.fn
    [RVSNew]/[webpack]/lib/rules/RuleSetCompiler.js:220:20
  
  - RuleSetCompiler.js:99 execRule
    [RVSNew]/[webpack]/lib/rules/RuleSetCompiler.js:99:21
  
  - RuleSetCompiler.js:118 execRule
    [RVSNew]/[webpack]/lib/rules/RuleSetCompiler.js:118:6
  
  - RuleSetCompiler.js:137 Object.exec
    [RVSNew]/[webpack]/lib/rules/RuleSetCompiler.js:137:6
  
  - NormalModuleFactory.js:403 
    [RVSNew]/[webpack]/lib/NormalModuleFactory.js:403:34
  
  - NormalModuleFactory.js:116 
    [RVSNew]/[webpack]/lib/NormalModuleFactory.js:116:11
  
  - NormalModuleFactory.js:544 
    [RVSNew]/[webpack]/lib/NormalModuleFactory.js:544:8
  
  - Hook.js:18 Hook.CALL_ASYNC_DELEGATE [as _callAsync]
    [RVSNew]/[webpack]/[tapable]/lib/Hook.js:18:14
  
  - NormalModuleFactory.js:542 
    [RVSNew]/[webpack]/lib/NormalModuleFactory.js:542:8
  
  - child-compiler.js:159 
    [RVSNew]/[html-webpack-plugin]/lib/child-compiler.js:159:18
  
  - Compiler.js:511 
    [RVSNew]/[webpack]/lib/Compiler.js:511:11
  
  - Compiler.js:1059 
    [RVSNew]/[webpack]/lib/Compiler.js:1059:17
  
  - task_queues:93 processTicksAndRejections
    node:internal/process/task_queues:93:5

Maybe we could at least wrap it with a try catch and let the user know which rule caused the error?

@sokra
Copy link
Member

sokra commented Dec 17, 2020

ok I reviewed the behavior again and noticed that when a property doesn't exist at all the matcher is called with "" too. When considering that it's a bit inconsistent that the behavior is not the same when a property is undefined. Usually undefined and not existing should be treated equally.

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

Successfully merging a pull request may close this issue.

3 participants