小编qwe*_*rty的帖子

使用 webpack typescript 和 esm 构建 Express 服务器

我正在尝试使用 构建一个小node.js + ts项目webpack

tsconfig.json
{
  "compilerOptions": {
    "lib": ["ESNext"],
    "target": "ES2020",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "esModuleInterop": true,
    "types": ["node"],
    "allowSyntheticDefaultImports": true,
    "rootDir": "./"
  },
}
Run Code Online (Sandbox Code Playgroud)

我将其添加到package.json行中"type": "module"

webpack.config.ts
import * as path         from 'path';
import * as webpack      from 'webpack';
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const PATHS = {
  entry:  path.resolve(__dirname, 'src/server/index.ts'),
  output: path.resolve(__dirname, 'dist'),
};

const config: webpack.Configuration = {
  target:  'node',
  entry:   PATHS.entry,
  output:  { …
Run Code Online (Sandbox Code Playgroud)

node.js typescript webpack es6-modules

7
推荐指数
1
解决办法
2092
查看次数

标签 统计

es6-modules ×1

node.js ×1

typescript ×1

webpack ×1