英文:
Unable to run Cypress open command in Next.js project with Typescript
问题 {#heading}
我无法运行Cypress open在我的Next.js项目中使用TypeScript。运行命令后,我得到以下结果。
mohitnayak@Mohits-MacBook-Pro todo-app % npm run cypress:open
> todo-app@0.1.0 cypress:open
> cypress open
DevTools listening on ws://127.0.0.1:50474/devtools/browser/067ddcd9-221c-4042-8544-08d3598b88d7
Missing baseUrl in compilerOptions. tsconfig-paths will be skipped
/Users/mohitnayak/Library/Caches/Cypress/12.17.3/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:311
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: ⨯ Unable to compile TypeScript:
error TS5095: Option 'bundler' can only be used when 'module' is set to 'es2015' or later.
at createTSError (/Users/mohitnayak/Library/Caches/Cypress/12.17.3/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:311:16)
at reportTSError (/Users/mohitnayak/Library/Caches/Cypress/12.17.3/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:314:23)
at /Users/mohitnayak/Library/Caches/Cypress/12.17.3/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:686:17
at Object.compile (/Users/mohitnayak/Library/Caches/Cypress/12.17.3/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:743:35)
at Module.m._compile (/Users/mohitnayak/Library/Caches/Cypress/12.17.3/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:856:36)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Object.require.extensions.<computed> [as .js] (/Users/mohitnayak/Library/Caches/Cypress/12.17.3/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:859:16)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Function.Module._load (node:internal/modules/cjs/loader:958:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
diagnosticCodes: [ 5095 ]
}
这是一个基本的待办事项应用程序。以下是打开GitHub仓库的链接。请帮助我为项目运行Cypress。
GitHub仓库
查看图片描述 英文:
I'm unable to run Cypress open in my Next.js project with Typescript. Here's what I get after running the command.
`mohitnayak@Mohits-MacBook-Pro todo-app % npm run cypress:open
> todo-app@0.1.0 cypress:open
> cypress open
DevTools listening on ws://127.0.0.1:50474/devtools/browser/067ddcd9-221c-4042-8544-08d3598b88d7
Missing baseUrl in compilerOptions. tsconfig-paths will be skipped
/Users/mohitnayak/Library/Caches/Cypress/12.17.3/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:311
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: ⨯ Unable to compile TypeScript:
error TS5095: Option 'bundler' can only be used when 'module' is set to 'es2015' or later.
at createTSError (/Users/mohitnayak/Library/Caches/Cypress/12.17.3/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:311:16)
at reportTSError (/Users/mohitnayak/Library/Caches/Cypress/12.17.3/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:314:23)
at /Users/mohitnayak/Library/Caches/Cypress/12.17.3/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:686:17
at Object.compile (/Users/mohitnayak/Library/Caches/Cypress/12.17.3/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:743:35)
at Module.m._compile (/Users/mohitnayak/Library/Caches/Cypress/12.17.3/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:856:36)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Object.require.extensions.<computed> [as .js] (/Users/mohitnayak/Library/Caches/Cypress/12.17.3/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:859:16)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Function.Module._load (node:internal/modules/cjs/loader:958:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
diagnosticCodes: [ 5095 ]
}
`
It's basic todo app. Here's the link to the open GitHub repo. Please help me running Cypress for the project.
GitHub repo
答案1 {#1}
得分: 4
前往您的tsconfig.json文件并更新该文件中moduleResolution的值。
例如:
"moduleResolution": "node"
在这里,您需要将值"bundler"替换为"node"。
我已测试过,这个更改可以正常工作。
更新后的结果:
Go to your tsconfig.json file and update the value of moduleResolution in this file.
i.e.
"moduleResolution": "node"
Here you need to replace the value "bundler" with "node".
I've tested and it works fine with this change.
Result after updating: