Closed alanhumphrey closed 1 year ago
Should mention this is on Win10
Could you make sure to update to the latest versions of the Cypress packages? This issue may have already been fixed. Thanks.
No problem. Here is my updated package.json:
{ "name": "my-vue-app", "version": "0.0.0", "scripts": { "dev": "vite", "build": "vite build", "serve": "vite preview", "cy": "cypress open-ct" }, "dependencies": { "@cypress/vite-dev-server": "^2.0.7", "@cypress/vue": "^3.0.3", "cypress": "^8.3.0", "vue": "^3.1.5" }, "devDependencies": { "@vitejs/plugin-vue": "^1.6.0", "@vue/compiler-sfc": "^3.1.5", "vite": "^2.1.5" } }
I deleted node_modules and reinstalled.
Error is still happening. Additional information:
This is the stack trace. (Same as before.)
at node_modules/@babel/types/lib/definitions/core.js (http://localhost:3000/__cypress/src/node_modules/.vite/@cypress_vue.js?v=a27e8a53:6670:22)
at require (http://localhost:3000/cypress/src/node_modules/.vite/chunk-75565K3H.js?v=a27e8a53:12:45)
at node_modules/@babel/types/lib/definitions/index.js (http://localhost:3000/__cypress/src/node_modules/.vite/@cypress_vue.js?v=a27e8a53:9637:6)
at require (http://localhost:3000/cypress/src/node_modules/.vite/chunk-75565K3H.js?v=a27e8a53:12:45)
at node_modules/@babel/types/lib/builders/builder.js (http://localhost:3000/__cypress/src/node_modules/.vite/@cypress_vue.js?v=a27e8a53:9666:25)
at require (http://localhost:3000/cypress/src/node_modules/.vite/chunk-75565K3H.js?v=a27e8a53:12:45)
at node_modules/@babel/types/lib/builders/generated/index.js (http://localhost:3000/__cypress/src/node_modules/.vite/@cypress_vue.js?v=a27e8a53:9954:21)
at require (http://localhost:3000/cypress/src/node_modules/.vite/chunk-75565K3H.js?v=a27e8a53:12:45)
at node_modules/@babel/types/lib/utils/react/cleanJSXElementLiteralChild.js (http://localhost:3000/__cypress/src/node_modules/.vite/@cypress_vue.js?v=a27e8a53:10720:23)
at require (http://localhost:3000/cypress/src/node_modules/.vite/chunk-75565K3H.js?v=a27e8a53:12:45)
From previous event:
at Object.runScripts (http://localhost:3000/__cypress/runner/cypress_runner.js:182127:22)
at $Cypress.onSpecWindow (http://localhost:3000/__cypress/runner/cypress_runner.js:171108:19)
at
FWIW - the very last error (initCypressTests.js:22:18) comes from
17 if (!CypressInstance) { 18 throw new Error('Tests cannot run without a reference to Cypress!') 19 }
Also - if I run 'cypress open' (not open-ct) all is well
The repository I was using was deprecated yesterday. Using the recommended repository (https://github.com/cypress-io/cypress-component-testing-examples.git) solves the "cannot read property 'emit' of undefined" error.
The error when the runner tries to execute a test is still there. Stack trace:
at node_modules/@babel/types/lib/definitions/core.js (http://localhost:51857/__cypress/src/node_modules/.vite/@cypress_vue.js?v=c970a3b8:6670:22)
at require (http://localhost:51857/cypress/src/node_modules/.vite/chunk-75565K3H.js?v=c970a3b8:12:45)
at node_modules/@babel/types/lib/definitions/index.js (http://localhost:51857/__cypress/src/node_modules/.vite/@cypress_vue.js?v=c970a3b8:9637:6)
at require (http://localhost:51857/cypress/src/node_modules/.vite/chunk-75565K3H.js?v=c970a3b8:12:45)
at node_modules/@babel/types/lib/builders/builder.js (http://localhost:51857/__cypress/src/node_modules/.vite/@cypress_vue.js?v=c970a3b8:9666:25)
at require (http://localhost:51857/cypress/src/node_modules/.vite/chunk-75565K3H.js?v=c970a3b8:12:45)
at node_modules/@babel/types/lib/builders/generated/index.js (http://localhost:51857/__cypress/src/node_modules/.vite/@cypress_vue.js?v=c970a3b8:9954:21)
at require (http://localhost:51857/cypress/src/node_modules/.vite/chunk-75565K3H.js?v=c970a3b8:12:45)
at node_modules/@babel/types/lib/utils/react/cleanJSXElementLiteralChild.js (http://localhost:51857/__cypress/src/node_modules/.vite/@cypress_vue.js?v=c970a3b8:10720:23)
at require (http://localhost:51857/cypress/src/node_modules/.vite/chunk-75565K3H.js?v=c970a3b8:12:45)
From previous event:
at Object.runScripts (http://localhost:51857/__cypress/runner/cypress_runner.js:182118:22)
at $Cypress.onSpecWindow (http://localhost:51857/__cypress/runner/cypress_runner.js:171099:19)
at
I have also run into this problem today with Cypress 8.3.1 on a vite-vue project, also on windows 10
in my project I'm also using cypress to run unit tests on a handful of composibles, and the tests for those work great. So I think this error is tied to the rendering of mounted components to the Vite server
I rolled back my dependencies, and cypress-ct worked for me, I re-updated my dependencies one by one to see where it would break. and from that testing the issue seems to come from @vue/compiler-sfc
when I upgraded @vue/compiler-sfc from 3.0.5 to 3.2.6 I got the Reference Error "process is not defined" error
I'm getting this too. Looking through the stack traces, it goes like this:
@cypress/vue
@vue/test-utils
vue
@vue/compiler-dom
@vue/compiler-core
@babel/types
@babel/types
added process.env.BABEL_TYPES_8_BREAKING
in v7.8.0
Not sure why this is needed at runtime, but you can work around it by adding
define: { 'process.env.BABEL_TYPES_8_BREAKING': 'false' }
to the vite config.
Can confirm. Adding the define to vite.config.js solved the problem
See https://github.com/vuejs/vue-next/issues/4531
- It can also be fixed in
@cypress/vue
by shipping an additional ESM bundle for Vite
Sounds like we should be shipping an additional ESM bundle. I think we already ship one though - what needs to be different about this one?
Here's our rollup config: https://github.com/cypress-io/cypress/blob/develop/npm/vue/rollup.config.js#L47
This should be fixed now in Vue 3.2.10
Sounds like we should be shipping an additional ESM bundle. I think we already ship one though - what needs to be different about this one?
😅 Sorry I missed that. Now I have to dig further to find out why Vite resolved to the CJS build of @vue/compiler-core
. It shouldn't happen unless some module in the dependency chain is a CJS module.
Now that Vue 3.2.10 removes the runtime dependency on @babel/types
, I think the workaround is fine.
That issue was a real problem anyway for pure CJS packages anyway.
As for removing the CJS alias in vite-dev-server
, maybe it can be addressed by adding an esm-browser
build for @vue/compiler-core
so that the esm-bundler
build can have more functionalities.
Let's discuss it in the vue-next
repo later.
Confusing - so it sounds like if you update your deps to the latest version of Vue (3.2.6, for example, and the compiler-sfc, etc etc) everything is okay?
Not clear if anything actually needs to be done in our Vite dev server at this point.
Been trying to get vue3 vite cypress working, but no matter which version I've tried I can't seem to get rid of this. Does anyone know a version that works with vue >=3.2.0 or if there's any workaround to get around this issue?
Relevant packages:
"vue": "^3.2.22",
"@cypress/vite-dev-server": "^2.2.1",
"@cypress/vue": "^3.0.5",
"cypress": "^9.1.0",
"@vitejs/plugin-vue": "^1.10.0",
"vite": "^2.6.14",
Update: Worked after I removed
server: {
port: serverPort,
strictPort: true,
https: {
key: fs.readFileSync('certs/localhost-key.pem'),
cert: fs.readFileSync('certs/localhost.pem'),
},
hmr: {
host: 'localhost',
port: 3005,
protocol: 'wss'
},
},
Didn't find a way to change server config option in plugins/index.ts, so I ended up creating seperate vite config files.
I just created a new project using vite, installed the cypress bits, and it worked. I did have to tweak cypress/plugins/index.js to add startDevServer, but that was just to get cypress open-ct to work.
Anyway, it basically worked out of the box. Is there any chance ../../node_modules/component-emitter is out of date?
I have seen that emit
error before. I think this is a red herring, the error is unrelated.
If you can share your minimal reproduction @olemarius, happy to take a look!
@lmiller1990 I think you're right, it's unrelated. It worked after I removed the ssl certs but the emit error persisted if I remember correctly. If you still would like a reproduction I can try to put that together, but can't promise when as things are a bit busy right now.
No actionable info, closing for now.
Current behavior
I'm running the example project found here:
https://github.com/cypress-io/cypress-component-examples/tree/main/vite-vue
When I run cypress open-ct the test browser opens. Selecting the HellowWorld.spec.js test results in a: Reference Error "process is not defined" message.
The console shows:
The stack trace is:
Desired behavior
The test should execute
Test code to reproduce
See above - I'm using the example code. My only modification to the code is to add
"cy" : "cypress open-ct"
to the scripts section of package.json
I execute the following from a visual studio terminal
npm run cy
Cypress Version
8.0.0
Other
Here are the dependencies from package.json: