Skip to content

Commit c39f955

Browse files
committed
Fix Vite CJS build warning for Yarn and Vue (#1722)
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]>
1 parent 4b6b0cb commit c39f955

File tree

4 files changed

+44
-38
lines changed

4 files changed

+44
-38
lines changed

react/yarn-pnp/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "buf-yarn-pnp",
33
"packageManager": "[email protected]",
44
"private": true,
5+
"type": "module",
56
"scripts": {
67
"start": "vite --port 3000",
78
"build": "tsc && vite build",

vue/cypress.config.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { defineConfig } from "cypress";
2+
import webpackPreprocessor from "@cypress/webpack-preprocessor";
3+
import ResolveTypeScriptPlugin from "resolve-typescript-plugin";
4+
5+
// Note that vue scaffolds a cypress config with a .ts extension, but this doesn't
6+
// work with ESM modules. Renaming this file to have a .js extension fixes the issue.
7+
// See: https://github.com/cypress-io/cypress/issues/23552
8+
9+
const options = {
10+
webpackOptions: {
11+
resolve: {
12+
extensions: [".ts", ".tsx", ".js"],
13+
plugins: [new ResolveTypeScriptPlugin()],
14+
},
15+
module: {
16+
rules: [
17+
{
18+
test: /\.tsx?$/,
19+
loader: "ts-loader",
20+
options: { transpileOnly: true },
21+
},
22+
],
23+
},
24+
},
25+
};
26+
27+
export default defineConfig({
28+
e2e: {
29+
specPattern: "cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}",
30+
baseUrl: "http://localhost:4173",
31+
setupNodeEvents(on) {
32+
on("file:preprocessor", webpackPreprocessor(options));
33+
},
34+
},
35+
36+
component: {
37+
devServer: {
38+
framework: "vue",
39+
bundler: "vite",
40+
},
41+
},
42+
});

vue/cypress.config.ts

-38
This file was deleted.

vue/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "buf-vue",
33
"version": "0.0.0",
4+
"type": "module",
45
"scripts": {
56
"start": "vite",
67
"build": "run-p type-check build-only",

0 commit comments

Comments
 (0)