-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The package may have incorrect main/module/exports specified in its package.json #12446
Comments
Hello @nemonemi. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
A minimal reproduction is needed to address this issue. |
@fi3ework it is tricky to simulate it because it depends on several systems. This would take quite a while to set up, and I don't think 3 days is enough for me to set this up, taking my other daily tasks into consideration. Before adding Vite, I've been using only Webpack, and everything worked as expected. The point that I'm getting at here is that there's a difference in parsing on the Vite side of this type of code: 'use strict';
var React$1 = require('react');
var reactUse = require('react-use');
var utils = require('@mui/material/utils');
var O = require('optics-ts');
var deepEqual = require('fast-deep-equal/es6');
var SearchIcon = require('@mui/icons-material/ManageSearchRounded');
var MuiButton = require('@mui/material/Button');
var ArrowDropDownIcon = require('@mui/icons-material/ArrowDropDownRounded');
var DropUpIcon = require('@mui/icons-material/ArrowDropUpRounded');
var ClickAwayListener = require('@mui/material/ClickAwayListener'); compared to this type of code: import * as React$1 from 'react';
import React__default, { useContext, useMemo, useState, useCallback, useRef, useLayoutEffect, useEffect, forwardRef, createRef, createContext } from 'react';
import { useGetSet } from 'react-use';
import { debounce } from '@mui/material/utils';
import * as O from 'optics-ts';
import deepEqual from 'fast-deep-equal/es6';
import SearchIcon from '@mui/icons-material/ManageSearchRounded';
import MuiButton, { buttonClasses } from '@mui/material/Button';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDownRounded';
import DropUpIcon from '@mui/icons-material/ArrowDropUpRounded';
import ClickAwayListener from '@mui/material/ClickAwayListener'; Is there a way to configure Vite to take either the Legacy or Modern, or to inform it to parse the Modern one? |
I'm afraid not, Vite's fundamental idea is based on native ESM (modern), although there's @vitejs/plugin-legacy, it only works on production mode. |
I've experienced a similar issue recently at work. (forgive me as i'm mostly backend these days) We have an internal UI library that we import to various react projects which use webpack. I started a new project in wails.io which uses vite. We were getting this exact error for our UI library We also had both a Additionally, our UI library is targeting |
@fi3ework my preferred solution would be for Vite to recognize the ESM (modern) version that it is accessing from the Removing the module property or setting it to return the legacy code, although it would suffice, is not really the point here or possible in some cases. |
Vite recognizes module field (link) and also could handle ESM imports and ES5 syntax. So a reproduction is needed to address the specific issue. |
Describe the bug
I am importing our custom UI library, which is an NPM package that has the following defined in its package.json.
When I run the build I get an error pointing me toward this package.json
When I adjust the
module
to point to theindex.js
everything works fine and as expectedThe difference between the
index.js
andindex.modern.js
is that theindex.modern.js
is not transpiled, so it hasimport
s,const
s etc.Reproduction
Cannot provide it at the moment
Steps to reproduce
No response
System Info
The text was updated successfully, but these errors were encountered: