首页 > 编程语言 >fix ts-node esm error All In One

fix ts-node esm error All In One

时间:2023-03-22 18:45:32浏览次数:85  
标签:node fix error ts https xgqfrms esm com

fix ts-node esm error All In One

error ❌

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"

ESM solution ✅

image

"type": "module", & ts-node-esm

{
  "name": "patch-package-in-action",
  "version": "1.0.0",
  "description": "patch-package in action",
  "main": "./src/index.ts",
  "type": "module",
  "scripts": {
    "dev-esm": "npx ts-node-esm ./src/index.ts",
    "app-esm": "npx ts-node-esm ./src/app.ts",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/web-fullstack/patch-package-in-action.git"
  },
  "author": "xgqfrms",
  "license": "MIT",
  "dependencies": {
    "lodash-es": "^4.17.21",
    "typescript": "^5.0.2"
  },
  "devDependencies": {
    "@types/lodash-es": "^4.17.7",
    "app-node-env": "^1.4.7",
    "rimraf": "^4.4.0",
    "ts-node": "^10.9.1"
  }
}


esm

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  },
  "ts-node": {
    "esm": true
  },
}

lodash-es


import {toString} from "lodash-es";

type Obj = {
  [key: string]: any;
}

const obj: Obj = {
  name: 'xgqfrms',
  country: 'China',
  language: 'zh-hans',
};

const str = toString(obj);
console.log(`toString =`, str1);

https://github.com/web-fullstack/patch-package-in-action

(

标签:node,fix,error,ts,https,xgqfrms,esm,com
From: https://www.cnblogs.com/xgqfrms/p/17245062.html

相关文章