Production build generates the exported default as the module itself
See original GitHub issueDescribe 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:
running vite build && vite preview
outputs:
Reproduction
- clone https://github.com/Newbie012/vite-bug-1
npm install
npm run dev
- see that the console.log that mentioned above exports accordingly
npm run build
npm run preview
- 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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Closing in favor of vite v3 which doesn’t use @rollup/plugin-commonjs
Decided to still open it since I believe it’s still a bug