I'm building a server with NodeJS, Typescript, Typeorm and ts-node.
The first line in one of my files I'm importing:
import { build } from 'compassql/build/src/schema';
And, when I run the code I got the error:
/Users/paulomenezes/repositories/juno/server/node_modules/compassql/build/src/schema.js:1
import dlBin_ from 'datalib/src/bins/bins';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (node:internal/modules/cjs/loader:1024:16)
at Module._compile (node:internal/modules/cjs/loader:1072:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Object.require.extensions.<computed> [as .js] (/Users/paulomenezes/repositories/juno/server/node_modules/ts-node/src/index.ts:384:14)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:997:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/Users/paulomenezes/repositories/juno/server/src/service/dashboard.service.ts:1:1)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
[nodemon] app crashed - waiting for file changes before starting...
The lib that I'm importing is CompassQL.
The error isn't in my project, but it's in the library, when I open the /node_module/compassql/build/src/schema.js, the javascript file has a import syntax:
import dlBin_ from 'datalib/src/bins/bins';
And I think that is the error, my dependency is using a syntax that is not supported in my project, but how I can fix this?
This is my tsconfig.json
"compilerOptions": {
"target": "ESNext",
"module": "CommonJS",
"moduleResolution": "node",
"outDir": "./build",
"rootDir": "./src",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"suppressImplicitAnyIndexErrors": true,
"declaration": true,
"noErrorTruncation": true,
"sourceMap": true,
"esModuleInterop": true,
"skipLibCheck": true,
"importHelpers": true,
"strict": false,
"allowJs": true,
"allowSyntheticDefaultImports": true
},
"include": [
"./node_modules/compassql/typings/*.d.ts",
"./node_modules/vega-lite/typings/*.d.ts",
"./node_modules/@types/**/*.d.ts",
"test/**/*.ts",
"typings/*.d.ts",
"typings/**/*.d.ts",
"src/**/*.ts"
],
"exclude": ["./node_modules/compassql/typings/json.d.ts", "./node_modules/vega-lite/typings/json.d.ts", "./node_modules/vega-lite/typings/vega.d.ts"]
}
And here is my package.json
{
"name": "server",
"version": "0.0.1",
"description": "Awesome project developed with TypeORM.",
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@types/cors": "^2.8.7",
"@types/d3": "^6.2.0",
"@types/express": "^4.17.7",
"@types/morgan": "^1.9.1",
"@types/multer": "^1.4.4",
"@types/node": "^8.0.29",
"@types/papaparse": "^5.2.2",
"husky": "^4.3.6",
"nodemon": "^2.0.4",
"ts-node": "3.3.0",
"typescript": "^4.1.3",
"yalc": "^1.0.0-pre.49"
},
"dependencies": {
"@junoapp/common": "file:.yalc/@junoapp/common",
"body-parser": "^1.19.0",
"clickhouse": "^2.1.5",
"compassql": "^0.21.2",
"cors": "^2.8.5",
"datalib": "^1.9.3",
"date-fns": "^2.16.0",
"express": "^4.17.1",
"firstline": "^2.0.2",
"got": "^11.7.0",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"papaparse": "^5.3.0",
"pg": "^8.3.0",
"reflect-metadata": "^0.1.10",
"typeorm": "0.2.25",
"vega-typings": "^0.19.2",
"winston": "^3.3.3"
},
"scripts": {
"start": "nodemon --max-old-space-size=8000 --watch 'src/**/*.ts' --ignore 'src/**/*.spec.ts' --exec 'ts-node' src/index.ts",
"yalc:update": "yalc update"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
My project complies normally without this import:
import { build } from 'compassql/build/src/schema';