require.resolve (called at runtime) is not transformed
Closed this issue · 1 comments
SpadarShut commented
Describe the bug
The require.resolve('foo')
calls do not get transformed and throw errors at runtime.
Reproduction
https://github.com/SpadarShut/vite-require-resolve
import { getThemeVariables } from 'antd/dist/theme';
getThemeVariables(); // throws Uncaught TypeError: __require.resolve is not a function
// getThemeVariables looks like this:
function getThemeVariables(options = {}) {
let themeVar = {
'hack': `true;@import "${require.resolve('antd/lib/style/color/colorPalette.less')}";`,
...defaultTheme
};
// ...
}
I believe vite should transform such require calls into resolved paths.
System Info
System:
OS: macOS 11.4
CPU: (4) x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
Memory: 258.35 MB / 8.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.4.0 - /usr/local/bin/node
npm: 7.19.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Browsers:
Chrome: 91.0.4472.164
Safari: 14.1.1
npmPackages:
vite: ^2.3.8 => 2.4.3
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.
yyx990803 commented
require.resolve
is a Node.js only API and esbuild doesn't support it. This is a wont fix. Antd should not rely on require.resolve
in client-oriented code. AFAIK webpack is the only bundler that supports it - basically this means Antd will only work in webpack - which, IMO, is a bad decision.