I am trying to create a simple node.js cli tool called convertxml. I have defined the bin field in my package.json and ran npm link.
When I run it, I am getting the following error when I run convertxml in powershell/cmd.
using the following package.json:
with the following tsconfig:
{
"compilerOptions": {
"incremental": true,
"target": "ES5",
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
],
"jsx": "preserve",
"module": "ES6",
"moduleResolution": "node",
"resolveJsonModule": true,
"noEmit": true,
"isolatedModules": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules",
"**/*.js"
]
}
The weird thing is that when I run node ./converter.js it runs perfectly.
Anyone knows how to solve this?
Related
I am trying obtain matches for a particular string using regex in my js script. The files I depend on are written in typescript. Below is a sample of the script to match text within curly braces:
//sampleRegex.ts
const dynamicRegex = /{(\w+)}/gmi;
const [v1] = 'hello {type}'.matchAll(dynamicRegex)
console.log(v1);
When I attempt to run the script using ts-node ts-node sampleRegex.ts, undefined is logged to the screen however when I try the exact same script in a js file with node sampleRegex.js I get the appropriate output shown below
I am trying to figure out why that is and how to get is in ts-node
//tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"es6",
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": false,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"sourceMap": true,
"noFallthroughCasesInSwitch": true,
"typeRoots": [
"#types",
"node_modules/#types"
]
},
"include": [
"src"
],
"exclude": [
"src/sw*"
]
}
I'm trying to run my server locally during development. I just run my .ts files, I don't run the js files generated to my dist folder.
When I run this script though that lives in my src/client/package.json:
"start-static-server": "node --experimental-json-modules --loader ts-node/esm.mjs ../server/server.ts",
I'm getting this error. src/client/node_modules definitely has ts-node installed so not sure why this is complaining:
src/client/node_modules/ts-node/src/index.ts:594
return [output.outputFiles[1].text, output.outputFiles[0].text]
^
TypeError: Cannot read property 'text' of undefined
src/client/tsconfig.json
{
"compilerOptions": {
"noEmit": false,
"outDir": "../../dist",
"target": "ES2020",
"module": "esnext",
"lib": [
"es5",
"es6",
"dom"
],
"typeRoots": ["node_modules/#types"],
"moduleResolution": "node",
"allowJs": false,
"jsx": "react",
"noImplicitAny": false,
"sourceMap": false,
"inlineSources": false,
"removeComments": true,
"noUnusedLocals": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"preserveSymlinks": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"."
],
"exclude": [
"../node_modules",
"**/node_modules/*",
"node_modules/#types",
"node_modules/#types/*",
"node_modules/#types/**",
"js/ink-config.js",
"test/**/*",
"ext",
"../../dist",
"wallaby.ts",
]
}
How do you stop tsc from processing a Javascript file required by another?
I want to run full checks on my main index.js, but it requires() a generated.js Javascript file created by emcc, which is perfectly fine, but doesn't pass a lot of tsc's checks.
I tried adding the file to my exclude list in my tsconfig.json, like:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": [
"dom",
"webworker"
],
"allowJs": true,
"checkJs": true,
"outDir": "./dist",
"noImplicitAny": false,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"index.js"
],
"exclude": [
"generated.js"
]
}
but that had no effect. When I run tsc --build tsconfig.json I get a tone of errors from generated.js.
The tsconfig.json file looks for typescript files by default, while you are providing it .js files. you can change the file extensions from .js to .ts to let typescript look after them. so your tsconfig.json file may end up looking like this:
{
"compilerOptions": {
"target": "es5",
"module": "system",
"lib": [
"dom",
"webworker"
],
"allowJs": true,
"checkJs": true,
"outDir": "./dist",
"noImplicitAny": false,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"index.ts"
],
"exclude": [
"node_modules",
"generated.ts"
]
}
I can't fix next error: when I build project for production, building is successfull. But when I build project with param --prod it's fail.
Error like this:
in node_modules\ng-zorro-antd\antd.d.ts.ɵep.html(1,999): : Object is possibly 'null'.
My TSlint setup is:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"strict": true,
"target": "es5",
"typeRoots": [
"node_modules/#types"
],
"lib": [
"es2017",
"dom"
],
"removeComments": true
},
"exclude": [
"node_modules",
"**/*.spec.ts",
"**/*.ts.ɵin.html"
]
}
I tried to add node_modules folder to "exclude" but it doesn't work.
I'm getting a load of errors when I run Karma Start in my angular project.
All the errors say: 'Cannot find name Blob', 'Cannot Find name KeyboardEvent', 'Cannot find name HTMLElement', etc.
my tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2016",
"dom"
],
"typeRoots": [
"./node_modules/#types/"
],
"types": [
"jasmine",
"node",
"core-js"
]
}
}
Help!
adding "dom" to lib in tsconfig.app.json fixed it