How to fix TypeScript tsc CLI option --jsx errors All In One
tsc
--jsx
❌
errors
error TS6142: Module '' was resolved to '/index.tsx', but '--jsx' is not set.
$ npm run dev
> ts-playground@1.0.0 dev
> tsc ./src/index.ts
src/index.ts:1:38 - error TS6142: Module './auto-login' was resolved to '/home/eric/Desktop/ts-playground/src/auto-login/index.tsx', but '--jsx' is not set.
1 export { default as AutoLogin } from './auto-login';
~~~~~~~~~~~~~~
src/index.ts:2:37 - error TS6142: Module './auto-login' was resolved to '/home/eric/Desktop/ts-playground/src/auto-login/index.tsx', but '--jsx' is not set.
2 export type { AutoLoginProps } from './auto-login';
~~~~~~~~~~~~~~
Found 2 errors in the same file, starting at: src/index.ts:1
error TS5023: Unknown compiler option '--jsx=react'.
$ npx tsc ./src/index.ts --jsx='react'
error TS5023: Unknown compiler option '--jsx=react'.
solutions
- use ``
- cli
# ✅ usage
$ npx tsc ./src/index.ts --jsx react
# ❌ usage
$ npx tsc ./src/index.ts --jsx='react'
demos
{
"compilerOptions": {
"target": "es6",
// "module": "esnext",
"module": "commonjs",
"moduleResolution": "node",
"rootDir": "src",
"outDir": "lib",
"lib": ["dom", "es2015"],
// "jsx": "react",
// "jsx": "preserve",
"jsx": "react-jsx",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"allowJs": true,
"checkJs": false,
"resolveJsonModule": true,
"esModuleInterop": true
},
"include": [
// "src/**/*",
"src/*.ts",
"src/**/*.tsx",
],
"exclude": [
"node_modules/**/*",
"types"
]
}
{
"name": "ts-playground",
"version": "1.0.0",
"description": "ts",
"main": "lib/index.js",
"scripts": {
"app": "tsc",
"dev": "tsc ./src/index.ts --jsx react",
"dev-bug": "tsc ./src/index.ts --jsx=react",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"ts"
],
"author": "xgqfrms",
"license": "MIT",
"devDependencies": {
"@types/node": "^20.8.4",
"@types/react": "^18.2.28",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^5.2.2"
}
}
(? 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
refs
https://stackoverflow.com/questions/50432556/cannot-use-jsx-unless-the-jsx-flag-is-provided
https://www.typescriptlang.org/docs/handbook/compiler-options.html
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 ?️,侵权必究⚠️!
- TypeScript errors option How CLItypescript errors option how abort_on_error asan_options options without typescript node how esm typescript_error typescript default export error type typescript expression error typescript_error typescript函数error number运算符typescript_error typescript locale linux error how how