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.

I'm having trouble with javascript thiry-party

See original GitHub issue

I’m learning a lot with react but I’m having a difficulty with javascript third-party.

I need to embed a javascript Snap.svg to my homepage npm install snapsvg (detail: https://github.com/adobe-webplatform/Snap.svg)

The way to import snapsvg is by using this code:

const Snap = require(`imports-loader?this=>window,fix=>module.exports=0!snapsvg/dist/snap.svg.js`);

But this occurs a following error: Module not found: 'imports-loader' in ...

I installed imports-loader and it does not work.

What is another alternative without using eject?


npm ls react-scripts: react-scripts@0.9.5 node -v: v7.7.3 npm -v: 4.4.1 Operating system: macOS Sierra

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gaearoncommented, Mar 24, 2017

Hi! We don’t support Webpack-specific syntax like this. Since they don’t provide a CommonJS entry point, your best bet is to:

  • Copy snap.svg-min.js into your public folder (preferably with a version, e.g. snap.svg@0.5.1-min.js).
  • Open public/index.html and add <script src="%PUBLIC_URL%/snap.svg@0.5.1-min.js"></script> to its <head>.
  • Add const Snap = window.Snap; in any file where you want to use it, and you’re good to go.

You can also ask them to provide a CommonJS entry point that doesn’t require fiddling with Webpack.

Hope it helps!

0reactions
phu-tang-tikicommented, Sep 1, 2018

Hi @gaearon,

I saw the same problem with @Tectract . Below is the code of browserSolc https://github.com/ericxtang/browser-solc I have to sleep 1 second and everything is ok. So weird 😦 I downloaded and added to header of html file <script src="%PUBLIC_URL%/browser-solc.min.js"></script>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loading Third-Party JavaScript - web.dev
When scripts in third-party iframes take a long time to run, they can block the main thread delaying other tasks from running. These...
Read more >
Debugging and Fixing Common JavaScript Errors Third Party ...
Here's what you'd learn in this lesson: Inspecting a code error, Todd determines a bug is occurring due to a third party vendor's...
Read more >
Things to Know (and Potential Dangers) with Third-Party Scripts
A third-party script might have unintended consequences · Overwriting your variables · Creating unnecessary risks by using eval · Changing your ...
Read more >
Run a piece of JavaScript as soon as a third-party script fails ...
We want to run some code after the browser finishes attempting to load a third-party script, so we can check whether it loaded...
Read more >
Running Third-Party JavaScript - YouTube
Adopt the right emerging trends to solve your complex engineering challenges at QCon London March 27-29, 2023. Get practical inspiration and ...
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