fix ts-node esm error All In One
fix ts-node esm error All In One
error ❌
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"
ESM solution ✅
"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
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
refs
https://typestrong.org/ts-node/docs/imports/
https://github.com/xgqfrms/one-line-awesome-js-code/issues/1
https://www.cnblogs.com/xgqfrms/p/17242430.html#5160380
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17245062.html
未经授权禁止转载,违者必究!