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

test: use ES syntax in vite.config.noexternal.js #8857

Merged
merged 3 commits into from
Jun 30, 2022

Conversation

stefanvanherwijnen
Copy link
Contributor

Description

Running pnpm run build:noExternal in ssr-vue playground results require/module is not defined errors, e.g.:

> test-ssr-vue@0.0.0 build:server:noExternal
> vite build --config vite.config.noexternal.js --ssr src/entry-server.js --outDir dist/server

▲ [WARNING] The CommonJS "module" variable is treated as a global variable in an ECMAScript module and may not work as expected [commonjs-variable-in-esm]

    vite.config.noexternal.js:5:0:
      5 │ module.exports = Object.assign(config, {
        ╵ ~~~~~~

  This file is considered to be an ECMAScript module because the enclosing "package.json"
  file sets the type of this file to "module":

    package.json:5:10:
      5 │   "type": "module",
        ╵           ~~~~~~~~

failed to load config from /home/stefan/Projects/vite/playground/ssr-vue/vite.config.noexternal.js
error during build:
ReferenceError: module 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/stefan/Projects/vite/playground/ssr-vue/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///home/stefan/Projects/vite/playground/ssr-vue/vite.config.noexternal.js?t=1656524183085:5:1
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at ESMLoader.import (node:internal/modules/esm/loader:409:24)
    at loadConfigFromFile (file:///home/stefan/Projects/vite/packages/vite/dist/node/chunks/dep-e7bffd95.js:62313:31)
    at resolveConfig (file:///home/stefan/Projects/vite/packages/vite/dist/node/chunks/dep-e7bffd95.js:61928:28)
    at doBuild (file:///home/stefan/Projects/vite/packages/vite/dist/node/chunks/dep-e7bffd95.js:43024:20)
    at build (file:///home/stefan/Projects/vite/packages/vite/dist/node/chunks/dep-e7bffd95.js:43013:16)
    at CAC.<anonymous> (file:///home/stefan/Projects/vite/packages/vite/dist/node/cli.js:747:9)
 ELIFECYCLE  Command failed with exit code 1.

Converting vite.config.noexternal.js to ES syntax fixes this.

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@netlify
Copy link

netlify bot commented Jun 29, 2022

Deploy Preview for vite-docs-main canceled.

Name Link
🔨 Latest commit ee484b2
🔍 Latest deploy log https://app.netlify.com/sites/vite-docs-main/deploys/62bc9194c015f40009e752fd

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find. Strange that this config wasn't ever used in the tests.

@patak-dev patak-dev changed the title fix: use ES syntax in vite.config.noexternal.js test: use ES syntax in vite.config.noexternal.js Jun 30, 2022
@patak-dev patak-dev merged commit 026eb18 into vitejs:main Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants