question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prevent that "require" is exposed as global function

See original GitHub issue

Why does parcel build create build files that expose a global require function and is there a way to prevent that?

// beginning of js build file
require=function(r,e,n) {...

🤔 Expected Behavior

When parcel is used to build libraries that are loaded on 3rd party websites, it should prevent to expose a global require function, because other scripts on that site could rely on a global require function.

😯 Current Behavior

When loading a JS file, which was built with parcel, it exposes require on the window object.

💁 Possible Solution

Add the possibility to configure, if require gets exposed or not.

🔦 Context

Loaded a JS build on a foreign website which relied on a different global require.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
klipsteincommented, Oct 22, 2018

@devinrhode2 the solution was that the function name require is not used anymore (which is utilized by RequireJS and some other loaders) and instead uses parcelRequire as global.

0reactions
devinrhode2commented, Oct 18, 2018

What was the solution? Does parcel still create it’s own require function?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you expose a global javascript function without ESLint ...
According to eslint.org adding /* export Counter */ should have worked, unless it's specifically for variables and not standalone functions.
Read more >
Avoid usage of global functions · Issue #3645 · twigphp/Twig
I'm currently using the box project and its php scoper but twig can currently not scoped away because of this global function requirements....
Read more >
globalThis - JavaScript - MDN Web Docs
Note: The globalThis property is configurable and writable so that code authors can hide it when executing untrusted code and prevent exposing ......
Read more >
why are globals bad in javascript [duplicate]
The global scope is not yours to mess with. The only legitimate reason for using the global scope is in order to expose...
Read more >
TypeScript: exposing module types in the global context and ...
So the initial idea was to take a few functions, wrap them in a module, load the module back into the global scope...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found