小编Joh*_*Lee的帖子

nextjs 12:错误 [ERR_REQUIRE_ESM]:必须使用 import 加载 ES 模块

custom-server-typescript尝试使用 example和 package安装 nextjs "type": "module"

当我运行时ts-node --project tsconfig.server.json server/index.ts,出现以下错误

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for D:\projects\trpgline-room3\server\index.ts
Run Code Online (Sandbox Code Playgroud)

这是我的设置 ts-node: 10.4.0 node: v16.13.1 npm: 8.3.0 nextjs: 12.0.7

这是我的tsconfig.server.json设置

{
  "extends": "./tsconfig.json",
  "include": ["server/**/*.ts"]
}

Run Code Online (Sandbox Code Playgroud)

这是我的tsconfig.json内容

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "ES2020",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true
  },
  "include": ["next-env.d.ts", "**/*.ts", …
Run Code Online (Sandbox Code Playgroud)

javascript node.js next.js

8
推荐指数
0
解决办法
1189
查看次数

标签 统计

javascript ×1

next.js ×1

node.js ×1