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

"Process script and link tags" example doesn't work #329

Closed
frangio opened this issue Oct 19, 2020 · 9 comments
Closed

"Process script and link tags" example doesn't work #329

frangio opened this issue Oct 19, 2020 · 9 comments

Comments

@frangio
Copy link

frangio commented Oct 19, 2020

  • Operating System: Arch Linux on Linux 5.8.13
  • Node Version: 12.9.0
  • NPM Version: 6 .14.8
  • webpack Version: 5.1.3 (cli 4.1.0)
  • html-loader Version: 1.3.2

Expected Behavior

Script tag with a src attribute to a file that is processed by file-loader should emit the script tag with the src pointing to the asset generated by Webpack.

Actual Behavior

The js file corresponding to the script tag is evaluated at bundle time.

npx webpack fails with:

ERROR in ./src/file.html
Module build failed (from ./node_modules/extract-loader/lib/extractLoader.js):
src/script.file.js:1
(function (exports, require, module, __filename, __dirname) { console.log(document);
                                                                          ^

ReferenceError: document is not defined

How Do We Reproduce?

I've just copied the example from the readme verbatim.

https://github.com/frangio/repro-webpack-html-loader

This has been reported before as #284, but since it's still unresolved with Webpack 5 I'm opening this issue.

@alexander-akait
Copy link
Member

Thank you for creating this issue. However, issues need to follow one of our templates so that we can clearly understand your particular circumstances.

Please help us help you by recreating the issue using one of our templates.

@alexander-akait
Copy link
Member

I will reopen this after you fix the problem

@frangio
Copy link
Author

frangio commented Oct 20, 2020

@evilebottnawi Done.

@alexander-akait
Copy link
Member

I see, but in extract-loader 😞 We can't fix it here 😞

@alexander-akait
Copy link
Member

You can avoid using document in favor this/globalThis

@frangio
Copy link
Author

frangio commented Oct 20, 2020

I don't think that would fix the issue. The javascript shouldn't be evaluted at all.

The example should probably be removed from the readme.

@terox
Copy link

terox commented Oct 21, 2020

@frangio I am experiencing the same issues.

The javascript is evaluated and it shouldn't be evaluated. The error comes from extract-loader but seems that there isn't any issue that notify that error recently. Then, is the example working with a specific version of extract-loader? Could we resolve it with an other pipeline? @evilebottnawi

@alexander-akait
Copy link
Member

Please open an issue in extract-loader repo, I don't know why evaluate this, if they need this, they should provide document object

@alexander-akait
Copy link
Member

Let' close in favor #259, we still not support some edge cases for style and script tags, we need improve this

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

No branches or pull requests

3 participants