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.

With output.environment.module, packaged dependency gets incorrect reference to external dependency

See original GitHub issue

Bug report

What is the current behavior? I’m building a react component library, so I declare react and react-dom as externals. I’m using webpack to build our library as a module, with experiments.outputModule = true, output.environment.module = true, and output.library.type = 'module'.

I’m using a library that also declares react as an external dependency.

When I do my build:

  • In the compiled code, we end up getting a reference to react as external_react_
  • my code’s calls to React.createContext get compiled correctly as external_react_.createContext()
  • my dependency’s calls to React.createContext get compiled incorrectly as external_react_["default"].createContext()

This results in a hard crash in consumers of my library, because external_react_["default"] is undefined and then external_react_["default"].createContext() throws.

If the current behavior is a bug, please provide the steps to reproduce.

reproduction case: https://github.com/MustafaHaddara/webpack-external-repro-case

What is the expected behavior?

My dependency’s calls to React.createContext should get compiled as external_react_.createContext()

Other relevant information: webpack version: 5.65.0 Node.js version: 14.16.0, also reproduced with 16.7.0 Operating System: Additional tools:

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
MustafaHaddaracommented, Jan 10, 2022

ok, that makes sense.

thanks for your help!

1reaction
alexander-akaitcommented, Jan 10, 2022

How did you import it? I realized I got the main and module keys wrong in my package.json in my repro case so you might have been importing the root index.js, I’ve updated my reproduction case now.

I tested it using https://github.com/MustafaHaddara/webpack-external-repro-case/blob/main/es/index.js, just run this in browser or using Node.js (document will be undefined)

What is webpack version in CRA? Please run npm ls webpack

Read more comments on GitHub >

github_iconTop Results From Across the Web

Finding external dependencies in non-standard places #439
This is a common issue with environment modules which miss certain crucial environment variables (missing CMAKE_PREFIX_PATH is a classic). As a ...
Read more >
Handling Compiler and other Package Dependencies
E.g. a case wherein several modules are loaded and the user replaces a module upon which other modules currently loaded depend.
Read more >
'npm start' returns error: "There might be a problem with the ...
There might be a problem with the project dependency tree. It is likely not a bug in Create React App, but something you...
Read more >
Resolving PowerShell module assembly dependency conflicts
When writing a binary PowerShell module in C#, it's natural to take dependencies on other packages or libraries to provide functionality.
Read more >
Getting the dependencies right | MPS - JetBrains
All programming languages have a notion of "imports". In Java you get packages and the "import" statement. In Ruby or Python you have...
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