TypeScript + Playwright 错误:找不到模块

8
我遇到了在使用Playwright编写测试自动化时的问题。 运行测试时,在test.spec.ts中出现以下错误: 错误: 找不到模块 '@common/common' 代码: 'MODULE_NOT_FOUND' 如何解决这个问题?
下面是相关的代码: test.spec.ts
import { chromium, ChromiumBrowser, Page } from "playwright";
import { test, expect, PlaywrightTestConfig } from "@playwright/test";
import Common from "@common/common";

test.beforeAll(async ({ page }) => {

});

test.describe('Go test', () => {
  test('Test1', async ({ page }) => {
    console.log("1111111111");
  });
})

package.json

{
  "name": "type-sanity",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "ts-node -r tsconfig-paths/register src/main.ts",
    "test": "npx playwright test"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/randomstring": "^1.1.7",
    "playwright": "^1.14.0",
    "randomstring": "^1.2.1",
    "typescript": "^4.3.5"
  },
  "devDependencies": {
    "@playwright/test": "^1.14.0",
    "@types/node": "latest",
    "ts-node": "^10.1.0",
    "tsconfig-paths": "^3.10.1",
    "typescript-module-alias": "^1.0.2"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "outDir": "./dist",
    "baseUrl": ".",
    "types": [],
    "paths": {
      "@config/*": [
        "tests/config/*"
      ],
      "@common/*": [
        "src/common/*"
      ],
    }
  },
  "exclude": [
    "node_modules"
  ]
}
1个回答

8

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接