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.

Issues with some modules ?

See original GitHub issue

Describe the bug When I import @ethersproject/bignumber in a page I get the following error when loading the page :

500
Cannot read property 'BN' of undefined

TypeError: Cannot read property 'BN' of undefined
    at ../src.ts/bignumber.ts:12:18
    at instantiateModule (C:\dev\wighawag\test-svelte-kit\node_modules\vite\dist\node\chunks\dep-6e02b235.js:69027:166)

Logs

browser :

GET http://localhost:3000/ 500 (Internal Server Error)

cli:

[vite] Error when evaluating SSR module /node_modules/@ethersproject/bignumber/lib.esm/bignumber.js:
TypeError: Cannot read property 'BN' of undefined
    at ../src.ts/bignumber.ts:12:18
    at instantiateModule (C:\dev\wighawag\test-svelte-kit\node_modules\vite\dist\node\chunks\dep-6e02b235.js:69027:166) (x3)

To Reproduce A repo created out of npm init svelte@next here : https://github.com/wighawag/test-svelte-kit

yarn && yarn dev

Expected behavior can import es module

Severity This is a blocker as I rely on @ethersproject packages

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
benmccanncommented, Apr 14, 2021

Here’s an FAQ with tips for the standard solutions to loading packages in Vite: https://kit.svelte.dev/faq#how-do-i-fix-the-error-i-m-getting-trying-to-include-a-package

I’m not sure whether this is the same issue though

2reactions
GrygrFlzrcommented, Apr 1, 2021

This is a bug with Vite when bundling certain SSR dependencies and does not appear in a Vite template project because it does not perform SSR nor bundling.

You are correct that it should be in production dependencies, not dev dependencies, so that it can be bundled into the application. It looks like Vite is failing to see that @ethersproject/bignumber is referencing bn.js.

For a proper workaround that bundles the dependency into the application, do the following in svelte.config.cjs:

module.exports = {
  // ...
  kit: {
    // ...
    vite: {
      // ...
      optimizeDeps: {
        include: ['bn.js'],
      }
    }
  }
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

On modules and separation of concerns - Loris Leiva
It forces you to stay predictable and design a better separation of concerns between modules as the application evolves.
Read more >
Troubleshooting - Modules Anywhere - Regular Labs
Some slideshow modules or other fancy modules will not work properly when placed through Modules Anywhere. Some javascript based modules don't like to...
Read more >
Your problems with Java modules : r/java - Reddit
The biggest issue with introducing modules into a codebase so far is estimating who needs what package exported or even open as we...
Read more >
Problems with Python Modules - Stack Overflow
So for some reason I am having problems with modules. I have projects I made lets say 4 monthes ago that I downloaded...
Read more >
Performance and consistency issues when modules or driver ...
Provides a workaround for the performance issue when certain modules are loaded into SQL Server address space or certain filter drivers are ...
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