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.

Consider using static require dependencies

See original GitHub issue

There is an issue when using the package with https://github.com/jspm (sytemjs) https://github.com/jspm/registry/issues/221

this code uses dynamic requires https://github.com/netroy/image-size/blob/master/lib/index.js#L6-L15

and https://github.com/systemjs/systemjs can not handle it.

Actually it is importaint as image-size is used with css precompilers (such as LESS) and they have to be used in systemjs-builder worflow.

Would you consider chanding requires to static paths? Or addings static deps declarations in the beginning of the file?

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
pawlufelicecommented, Feb 4, 2016

This is a problem for me too!! I have browserify on an express app and the dynamic requires just to not get bundled, resulting in module not found. Please have them changed to static. Thanks

1reaction
danielweckcommented, Dec 13, 2017

Indeed, Browserify (which ; by the way ; is not only used for client-side bundling, but can also be used to package server-side code, e.g. in Electron) fails to fulfill the dynamic require() calls, for instance: https://github.com/image-size/image-size/blob/a71d6372c95e79efa0b349153a8525381aab0e5c/lib/index.js#L9-L14 (from the types list defined at https://github.com/image-size/image-size/blob/master/lib/types.js )

The current workaround is to add explicit requires for each “type” using a hard-coded path. This is actually standard practice in several CommonJS libs, to ensure Browserify (and others) compatibility.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use dependency injection in static class - Stack Overflow
You basically have two options: Change the class from static to an instance class and supply the dependency through Constructor Injection.
Read more >
Dependency Injection vs Static Dependencies
I was curious whether in a situation like this it is more appropriate to use poor man's di (no framework) or static class...
Read more >
Static classes are evil, or Make your dependencies explicit
Since classes with static methods have nothing to do with objects, they don't know who they are, what they should do and what...
Read more >
Using .NET Core DI in static class | by Mustafa Magdy - Medium
You may encounter a situation where you need to resolve a dependency inside a static class, but with static class you are limited...
Read more >
Breaking static dependency - Gunnar Peipman
This blog post introduces two tricks to make code with static dependencies testable. As a sample I take one piece of non-commercial code ......
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