Skip to content
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

Docs for MPA config incorrectly suggest using __dirname #9189

Closed
7 tasks done
SteveALee opened this issue Jul 18, 2022 · 1 comment
Closed
7 tasks done

Docs for MPA config incorrectly suggest using __dirname #9189

SteveALee opened this issue Jul 18, 2022 · 1 comment

Comments

@SteveALee
Copy link
Contributor

SteveALee commented Jul 18, 2022

Describe the bug

The docs for MPA config suggets using __dirname in the config file.

However, the config file is an ES module in my repo created from a template (can't recall exactly how). __dirname is not available in ES Modules, resulting in the following stack strace

failed to load config from /home/wsl/musical-parameters/vite.config.js
error during build:
ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/wsl/musical-parameters/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///home/wsl/musical-parameters/vite.config.js?t=1658086233703:13:23
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
    at async loadConfigFromFile (file:///home/wsl/musical-parameters/node_modules/vite/dist/node/chunks/dep-561c5231.js:62653:31)
    at async resolveConfig (file:///home/wsl/musical-parameters/node_modules/vite/dist/node/chunks/dep-561c5231.js:62281:28)
    at async doBuild (file:///home/wsl/musical-parameters/node_modules/vite/dist/node/chunks/dep-561c5231.js:43272:20)
    at async build (file:///home/wsl/musical-parameters/node_modules/vite/dist/node/chunks/dep-561c5231.js:43261:16)
    at async CAC.<anonymous> (file:///home/wsl/musical-parameters/node_modules/vite/dist/node/cli.js:747:9)

#6899 has a suitable but it dos not work

import { dirname } from 'node:path'
import { fileURLToPath } from 'url';
const _filename = fileURLToPath(import.meta.url);
const _dirname = dirname(_filename);

I've not provided a PR in case there is more going on.

Reproduction

N/A

System Info

N/A

Used Package Manager

npm

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented Jul 18, 2022

Fixed in #9121. Vite 3.0.1.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Aug 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants