Upon attempting to compile a ts file, I encountered the following error:
node_modules/@types/node/util.d.ts(121,88): error TS2304: Cannot find name 'Symbol'.
After some research, I found that this issue could be related to incorrect target or lib options specified in the tsconfig.json
file. I have made several attempts to resolve it by adjusting the target to "es15" and adding "es2015" to the lib field, but haven't had much success.
I am utilizing the following tutorial as a reference for my project:
Directory structure:
dist
lib
├──controllers
| ├──controller.ts
|
├──models
| ├──model.ts
|
├──routes
| ├──routes.ts
|
├──app.ts
├──server.ts
node_modules
package.json
tsconfig.json
tsconfig.json:
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"noImplicitThis": false,
"removeComments": true,
"experimentalDecorators": true,
"strictNullChecks": true,
"moduleResolution": "node",
"pretty": true,
"sourceMap": true,
"allowJs": true,
"noLib": false,
"jsx": "react",
"outDir": "./dist",
"lib": ["es2017"],
"baseUrl": "./lib"
},
"include": [
"lib/**/*.ts"
],
"exclude": [
"node_modules"
]
}
model.ts:
import * as mongodb from 'mongodb'
import * as fs from 'fs'
const filepath = __dirname + '/../file.txt'
function asyncReadFile(filepath: string, type: string) {
return new Promise((resolve, reject) => {
fs.readFile(filepath, (err, data) => {
console.log("Reading file...")
err ? reject(err) : resolve(data)
})
})
}
asyncReadFile(filepath, 'utf-8')