You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.
Describe the bug
You are not able to declare __dirname in ESM mode because import.meta is not available in the vite.config.ts.
I'm using the __dirname to find packages in monorepo.
Run vite
You will get undefined for metaUrl and an error for fileURLtoPath cuz it expects a string.
System Info
vite version: this is happening since beta 22
Operating System: Windows 10 but using WSL
Node version: 14.13.0
Package manager (npm/yarn/pnpm) and version: yarn 1.22.5
Logs (Optional if provided reproduction)
$ DEBUG=* yarn vite
yarn run v1.22.5
$ <workspace>/node_modules/.bin/vite
"import.meta" is not available in the configured target environment and will be empty
2 | import {fileURLToPath} from "url";
3 |
4 | const metaUrl = import.meta.url;
| ^
5 | console.log("meta-url", metaUrl);
6 | const __dirname = dirname(fileURLToPath(metaUrl));
meta-url undefined
failed to load config from <workspace>/vite.config.ts
error when starting dev server:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of URL. Received undefined
at fileURLToPath (internal/url.js:1348:11)
at data:text/javascript,import { dirname } from 'path';
import { fileURLToPath } from 'url';
const import_meta = {};
const metaUrl = import_meta.url;
console.log("meta-url", metaUrl);
const __dirname = dirname(fileURLToPath(metaUrl));
var vite_config = {};
export default vite_config;
:1:182
at ModuleJob.run (internal/modules/esm/module_job.js:146:23)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Loader.import (internal/modules/esm/loader.js:165:24)
at async loadConfigFromFile (<workspace>/node_modules/vite/dist/node/chunks/dep-478c65b9.js:46855:31)
at async resolveConfig (<workspace>/node_modules/vite/dist/node/chunks/dep-478c65b9.js:46650:28)
at async createServer$2 (<workspace>/node_modules/vite/dist/node/chunks/dep-478c65b9.js:65202:20)
at async CAC.<anonymous> (<workspace>/node_modules/vite/dist/node/cli.js:681:24)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The text was updated successfully, but these errors were encountered:
Describe the bug
You are not able to declare __dirname in ESM mode because
import.meta
is not available in the vite.config.ts.I'm using the __dirname to find packages in monorepo.
Reproduction
You will get undefined for metaUrl and an error for fileURLtoPath cuz it expects a string.
System Info
vite
version: this is happening since beta 22Logs (Optional if provided reproduction)
The text was updated successfully, but these errors were encountered: