Open haoqunjiang opened 11 months ago
IMO, getting rid of ts-node
may be a better option here. Because there are other well-known issues of this tool.
For example, it doesn't support solution-style tsconfigs, forcing us to specify a compilerOptions.module
option in the root tsconfig.json
, even though that field doesn't mean anything for any other tool. This is not a good DX.
The warning
The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
links also to
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.
currently caused by require.resolve.
// "vite-dev-server" is bundled in the binary, so we need to require.resolve "vite"
// from root of the active project since we don't bundle vite internally but rather
// use the version the user has installed
export function getVite (config: ViteDevServerConfig): Vite {
try {
const viteImportPath = require.resolve('vite', { paths: [config.cypressConfig.projectRoot] })
debug('resolved viteImportPath as %s', viteImportPath)
return require(viteImportPath)
} catch (err) {
throw new Error(`Could not find "vite" in your project's dependencies. Please install "vite" to fix this error.\n\n${err}`)
}
}
Any way to resolve this?
Current behavior
When using Cypress Component Testing with Vite 5, if
vite.config.ts
is used, a CJS Node API deprecation warning will always appear, despite"module": "NodeNext"
or"module": "ESNext"
being specified in the roottsconfig.json
and"type": "module"
being present inpackage.json
.Desired behavior
Should not show the CJS warning because
vite.config.ts
should be treated as an ES module whentype: "module"
presents.Test code to reproduce
The following warning will be printed:
and
The latter issue has already been tracked at https://github.com/cypress-io/cypress/issues/28347
Cypress Version
13.5.1
Node version
v18.18.2
Operating System
macOS 14.1
Debug Logs
No response
Other
I guess this is because of the limitation of
ts-node
that Cypress uses underlyingly to load the configuration files: https://github.com/TypeStrong/ts-node/issues/1791#issuecomment-1149754228Considering Vite 6 will drop CJS Node API, I think Cypress needs to either work around this limitation or move away from
ts-node
as early as possible.