无法在带有Typescript的Next.js项目中运行Cypress open命令。

huangapple go评论121阅读模式
英文:

Unable to run Cypress open command in Next.js project with Typescript

问题

我无法运行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.&lt;computed&gt; [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

enter image description here

答案1

得分: 4

前往您的tsconfig.json文件并更新该文件中moduleResolution的值。
例如:

"moduleResolution": "node"

在这里,您需要将值"bundler"替换为"node"。

我已测试过,这个更改可以正常工作。

更新后的结果:

无法在带有Typescript的Next.js项目中运行Cypress open命令。

英文:

Go to your tsconfig.json file and update the value of moduleResolution in this file.
i.e.

&quot;moduleResolution&quot;: &quot;node&quot;

Here you need to replace the value "bundler" with "node".

I've tested and it works fine with this change.

Result after updating:

无法在带有Typescript的Next.js项目中运行Cypress open命令。

huangapple
  • 本文由 发表于 2023年8月10日 20:27:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76875739.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定