Documented imports doesn't work
poslegm opened this issue · 3 comments
poslegm commented
Hello!
Thank you for this library.
I have typescript project which I runs with
tsc && node --es-module-specifier-resolution=node dist/server.js
I followed installation steps from README and received error in runtime:
(node:339743) ExperimentalWarning: The ESM module loader is experimental.
file:///home/poslegm/Documents/admin-service/dist/server.js:5
import { config } from "node-config-ts";
^^^^^^
SyntaxError: The requested module 'node-config-ts' does not provide an export named 'config'
node.js don't see generated Config.d.ts
.
But all works fine if I use config like this:
import config from "node-config-ts";
console.log(config.config.myField);
Is it deprecated documentation or something else?
poslegm commented
Node version: v13.12.0
Full package.json:
{
"name": "aaa",
"version": "1.0.0",
"description": "bbb",
"main": "dist/server.js",
"scripts": {
"start": "tsc && node --es-module-specifier-resolution=node dist/server.js",
"build": "tsc",
"test": "jest",
"postinstall": "node-config-ts"
},
"author": "xxxx",
"license": "yyyy",
"devDependencies": {
"@types/body-parser": "^1.19.0",
"@types/express": "^4.17.3",
"@types/express-pino-logger": "^4.0.2",
"@types/jest": "^25.1.4",
"@types/pino": "^5.17.0",
"@types/supertest": "^2.0.8",
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
"eslint": "^6.8.0",
"express-pino-logger": "^4.0.0",
"jest": "^25.2.3",
"mocha": "^7.1.1",
"node-config-ts": "^3.0.4",
"pino": "^6.1.1",
"pino-pretty": "^4.0.0",
"prettier": "2.0.1",
"supertest": "^4.0.2",
"ts-jest": "^25.2.1",
"typescript": "^3.8.3"
},
"dependencies": {
"express": "^4.17.1"
},
"type": "module",
"jest": {
"preset": "ts-jest"
}
}
Full tsconfig.json:
{
"compilerOptions": {
"incremental": true,
"target": "es6",
"module": "ES6",
"sourceMap": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist",
"moduleResolution": "node"
},
"include": ["src/**/*.ts", "config/**/*.ts"],
"exclude": ["node_modules"]
}
Config directory structure:
config
├── Config.d.ts
├── default.json
└── env
└── production.json
poslegm commented
Please let me know if I can help somehow
poslegm commented
I found the problem:
- "module": "ES6",
+ "module": "commonjs",
in tsconfig.json fixes the issue.