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",
]
}
Related
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?
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 am working in MacBook Pro in React. The project works well. But I am running this project on Windows 10 and it drops a lot of errors. Switching property allowSyntheticDefaultImports in true
does not lead to success. An error: 'An export assignment cannot be used in a module with other exported elements.'
TSconfig:
{
"compilerOptions": {
"outDir": "build",
"module": "esnext",
"target": "es5",
"downlevelIteration": true,
"lib": ["es6", "dom", "es2019.object", "es2016.array.include"],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "./src/",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowSyntheticDefaultImports" : false,
"plugins": [
{
"name": "typescript-tslint-plugin",
}
],
"baseUrl": "./src/",
"paths": {
"*": ["*"]
}
},
"exclude": [
"node_modules",
"cache",
"build",
"scripts",
"cypress",
"acceptance-tests",
"webpack",
"jest",
"config",
"src/setupTests.ts"
]
}
try adding "allowSyntheticDefaultImports": true in compilerOptions in
your tsconfig.json file and then use the syntax
Or try setting the esModuleInterop flag to true.
With flag esModuleInterop we can import CommonJS modules in compliance
with es6 modules spec
your file will look like this.
{
"compilerOptions": {
"outDir": "build",
"module": "esnext",
"target": "es5",
"downlevelIteration": true,
"lib": ["es6", "dom", "es2019.object", "es2016.array.include"],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "./src/",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowSyntheticDefaultImports" : false,
"plugins": [
{
"name": "typescript-tslint-plugin",
}
],
"baseUrl": "./src/",
"paths": {
"*": ["*"]
}
},
"exclude": [
"node_modules",
"cache",
"build",
"scripts",
"cypress",
"acceptance-tests",
"webpack",
"jest",
"config",
"src/setupTests.ts"
],
"esModuleInterop": true, //<----------------------------add this
"allowSyntheticDefaultImports": true //<----------------------------and this
}
I'm trying to compile a typescript project into javascript but for some reason, I keep getting the project's source files in the dist folder. I think it's something to do with my config but I've been through the docs and I can't find something about output folder structure or anything similar sounding. Here's my tsconfig:
{
"include": ["src", "types", "test"],
"compilerOptions": {
"target": "es5",
"module": "esnext",
"lib": ["dom", "esnext"],
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"baseUrl": "./",
"paths": {
"*": ["src/*", "node_modules/*"]
},
"jsx": "react",
"esModuleInterop": true
}
}
I am using tsdx and read in one of their issues that some config values are skipped. Is there anyone familiar with the library?
you can only remove the "src" in your first option called "include"
My React js project failed and I got many times this error:
The TS2339: property 'x' does not exist on value of type 'y'
my tsconfig.json file :
{
"compilerOptions": {
"jsx": "react",
"target": "es6",
"module": "esnext",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"outDir": "target/classes/static/app",
"lib": ["es2015", "es2017", "dom"],
"types": ["webpack-env", "jest"],
"allowJs": true,
"checkJs": false,
"baseUrl": "./",
"paths": {
"app/*": ["src/main/webapp/app/*"]
},
"importHelpers": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"include": ["src/main/webapp/app", "src/test/javascript/spec"],
"exclude": ["node_modules"]
}
How fix it?
Maybe adding this rule to tsconfig will help
"noImplicitAnyForClassMembers": false