我试图在Cypress中设置一个自定义的take,每当我将Typescript文件导入到我的cypress.config.ts
中时,都会遇到Cypress配置错误。
柏树配置ts
import 'dotenv-defaults/config';
import { defineConfig } from 'cypress';
import { MongoMemoryServer } from 'mongodb-memory-server';
import db from './src/server/db/datasource';
const createDb = async () => {
const server = await MongoMemoryServer.create();
try {
db.setOptions({ url: server.getUri() });
await db.initialize();
} catch (err) {
throw err;
}
return db;
};
export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
on('before:browser:launch', (browser, launchOptions) => {
if (browser.name === 'chrome') {
launchOptions.args.push('--proxy-bypass-list=<-loopback>');
launchOptions.args.push('--disable-dev-shm-usage');
launchOptions.args.push('--disable-gpu');
launchOptions.args.push('--no-sandbox');
return launchOptions;
}
});
on('task', {
log(message) {
console.log(message);
return null;
},
/* createDb() {
return createDb();
}, */
});
return config;
},
baseUrl: `http://localhost:${process.env.PORT || 3000}`,
video: false,
screenshotOnRunFailure: false,
modifyObstructiveCode: false, // Cypress utterly ruins Remix Context if this isn't disabled
chromeWebSecurity: false,
experimentalSessionAndOrigin: true,
experimentalSourceRewriting: true,
},
env: process.env,
});
上述文件import db from './src/server/db/datasource';
中的第四行破坏了配置并导致此错误:
您的配置文件无效:/home/project/cypress.config.ts类型错误[未知文件扩展错误]:/home/project/cypress.config.ts的未知文件扩展名“.ts”
我已经在谷歌上搜索了这个错误,它似乎是一个已知的与柏树,我已经尝试了所有的建议,包括升级柏树到最新版本(^10.11.0
),但没有帮助。
我试着用我的tsconfig.json做一些规划,但是没有什么效果。下面是这个文件:
{
"include": ["./*", "src", "test", "types", "scripts"],
"exclude": ["cypress" /* "./cypress.config.ts" */],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"module": "esnext",
"jsx": "react-jsx",
"moduleResolution": "node",
"target": "es2019",
"baseUrl": ".",
"rootDir": ".",
"isolatedModules": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"strict": true,
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"noEmit": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
"paths": {
"~/*": ["./src/*"],
"@test": ["./test"],
"@test/*": ["./test/*"]
}
},
"ts-node": {
"compilerOptions": {
"module": "commonjs"
}
}
}
我正在运行的命令启动cypress只是npx cypress open
。希望得到一些帮助,因为它不清楚是什么导致这个问题!
1条答案
按热度按时间flvtvl501#
用下方法修正
1.删除node_module文件夹
1.删除包锁.json·
1.运行npm缓存清理--force命令两次
1.运行npm i·