Skip to content

Commit

Permalink
Fix Vite CJS build warning for Yarn and Vue (#1722)
Browse files Browse the repository at this point in the history
Fixes #1721 

This fixes the warning about Vite's deprecated CJS build in the
`react/yarn-pnp` and `vue` projects by converting them to an ESM module.
Previously, they were both CJS, most likely due to a simple oversight.

With Vue, it also involved renaming the Cypress config to be a `.js`
file. Vue scaffolds Cypress config files to be a `.ts` file, which in
turn does not work with ESM modules. See [this
issue](cypress-io/cypress#23552) for more
info.

For more info on the Vite CJS message:
https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated

---------

Signed-off-by: Steve Ayers <[email protected]>
  • Loading branch information
smaye81 committed Aug 12, 2024
1 parent 4b6b0cb commit c39f955
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 38 deletions.
1 change: 1 addition & 0 deletions react/yarn-pnp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "buf-yarn-pnp",
"packageManager": "[email protected]",
"private": true,
"type": "module",
"scripts": {
"start": "vite --port 3000",
"build": "tsc && vite build",
Expand Down
42 changes: 42 additions & 0 deletions vue/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { defineConfig } from "cypress";
import webpackPreprocessor from "@cypress/webpack-preprocessor";
import ResolveTypeScriptPlugin from "resolve-typescript-plugin";

// Note that vue scaffolds a cypress config with a .ts extension, but this doesn't
// work with ESM modules. Renaming this file to have a .js extension fixes the issue.
// See: https://github.com/cypress-io/cypress/issues/23552

const options = {
webpackOptions: {
resolve: {
extensions: [".ts", ".tsx", ".js"],
plugins: [new ResolveTypeScriptPlugin()],
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "ts-loader",
options: { transpileOnly: true },
},
],
},
},
};

export default defineConfig({
e2e: {
specPattern: "cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}",
baseUrl: "http://localhost:4173",
setupNodeEvents(on) {
on("file:preprocessor", webpackPreprocessor(options));
},
},

component: {
devServer: {
framework: "vue",
bundler: "vite",
},
},
});
38 changes: 0 additions & 38 deletions vue/cypress.config.ts

This file was deleted.

1 change: 1 addition & 0 deletions vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "buf-vue",
"version": "0.0.0",
"type": "module",
"scripts": {
"start": "vite",
"build": "run-p type-check build-only",
Expand Down

0 comments on commit c39f955

Please sign in to comment.