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.

Production build generates the exported default as the module itself

See original GitHub issue

Describe the bug

When importing the package react-mapbox-wrapper, it behaves differently when used in development and production.

Given the following code:

import * as M from "react-mapbox-wrapper";
console.log(`M`, M);

running vite outputs:

image

running vite build && vite preview outputs:

image

Reproduction

  1. clone https://github.com/Newbie012/vite-bug-1
  2. npm install
  3. npm run dev
  4. see that the console.log that mentioned above exports accordingly
  5. npm run build
  6. npm run preview
  7. see that the console.log logs a module which its default module is itself

System Info

System:
    OS: Linux 4.19 Ubuntu 20.04.1 LTS (Focal Fossa)
    CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
    Memory: 14.32 GB / 24.99 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 12.22.6 - ~/.nvm/versions/node/v12.22.6/bin/node
    npm: 6.14.15 - ~/.nvm/versions/node/v12.22.6/bin/npm
  npmPackages:
    @vitejs/plugin-legacy: 1.6.4 => 1.6.4 
    @vitejs/plugin-react: 1.1.3 => 1.1.3 
    vite: 2.7.2 => 2.7.2

Used Package Manager

npm

Logs

No response

Validations

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Newbie012commented, Jun 26, 2022

Closing in favor of vite v3 which doesn’t use @rollup/plugin-commonjs

0reactions
Newbie012commented, Apr 10, 2022

Decided to still open it since I believe it’s still a bug

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I resolve eslint import/no-named-as-default
Removing the name of the class in ButtonBack.jsx ( export default class extends React.Component ) does not solve the issue either.
Read more >
Package exports - webpack
The exports field in the package.json of a package allows to declare which module should be used when using module requests like import...
Read more >
Understanding Modules and Import and Export Statements in ...
In this tutorial, you will learn what a JavaScript module is and how to use import and export to organize your code. Modular...
Read more >
Node.js Module Exports Explained | Scout APM Blog
CommonJS (CJS): Default in Node.js; uses module.exports and require ... create a dummy application to simulate the manufacturing, export, ...
Read more >
Documentation - Modules - TypeScript
How modules work in TypeScript. ... You can read more in the 3.8 release notes. Default exports. Each module can optionally export a...
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