Closed dbvcode closed 2 years ago
It might be related to your setup. I just tried a minimal nodeJs app with express and it seems to work correctly
package.json:
{
"name": "moralis-node-app",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@types/express": "^4.17.13",
"@types/node": "^16.9.1",
"ts-node-dev": "^1.1.8",
"typescript": "^4.4.3"
},
"dependencies": {
"express": "^4.17.1",
"moralis": "^1.2.7"
},
"scripts": {
"dev": "ts-node-dev ./src/index.ts",
"start": "tsc && node ./lib/index.js"
}
}
tsconfig:
{
"compilerOptions": {
"target": "es5" ,
"module": "commonjs" ,
"rootDir": "./src" ,
"baseUrl": "./src" ,
"outDir": "./lib",
"esModuleInterop": true ,
"forceConsistentCasingInFileNames": true ,
"strict": true ,
"useUnknownInCatchVariables": false ,
"skipLibCheck": true
},
"include": ["src"]
}
./src/index.ts
import Moralis from "moralis/node";
Moralis.start({
appId,
serverUrl,
});
This gives complete Typescript types
That's interesting.
In my case the types are there, but when I launch I have the problem.
If you do a console.log(Moralis)
do you have the Moralis object?
As I have stated above, mine is undefined
.
I don't have the esModuleInterop
option.
Yes correct, console.log(Moralis) returns the Moralis instance, and the code is type-checked. Please check if you can get it to work in a minimal app, without other dependencies and config, like I did above to confirm if it works.
Closing this issue as it is not a bug and likely because of config/environment/dependencies. If you need support, you can reach out on forum.moralis.io
New Bug Report
Checklist
Issue Description
The import of Moralis in a NodeJS Typescript project does not work as expected. There seems to be a object / types error. In the following scenarios: A: The object is there and does call the Moralis functions, but there is no Types assistance in the code. B: I have types assistance when I write the code but when I compile the object is undefined. C: A dirty hack that seems to work for now, but not sure if it's the right thing
Steps + code to reproduce
A:
B:
C:
Actual Outcome
A: logs the the Moralis object but does not assist in the code
B: logs
undefined
but provides assistance when writing codeC: logs Moralis object and also assists with the code
Expected Outcome
I would expect
import Moralis from 'moralis/node';
orimport {Moralis} from 'moralis/node';
to work out of the box.Environment
An NX workspace with a bunch of apps including the nodeJS one I'm playing with "@angular/animations": "13.1.1", "@angular/common": "13.1.1", "@angular/compiler": "13.1.1", "@angular/core": "13.1.1", "@angular/forms": "13.1.1", "@angular/platform-browser": "13.1.1", "@angular/platform-browser-dynamic": "13.1.1", "@angular/router": "13.1.1", "@capacitor/core": "^3.3.4", "@feathers-plus/cache": "^1.4.0", "@feathersjs/authentication": "^4.5.12", "@feathersjs/authentication-client": "^4.5.13", "@feathersjs/authentication-local": "^4.5.12", "@feathersjs/authentication-oauth": "^4.5.12", "@feathersjs/configuration": "^4.5.12", "@feathersjs/errors": "^4.5.12", "@feathersjs/express": "^4.5.12", "@feathersjs/feathers": "^4.5.12", "@feathersjs/socketio": "^4.5.13", "@feathersjs/socketio-client": "^4.5.13", "@feathersjs/transport-commons": "^4.5.12", "@ionic/angular": "^5.8.3", "@nrwl/angular": "13.4.3", "@pm2/io": "^5.0.0", "bignumber.js": "^9.0.2", "bson": "^4.6.1", "compression": "^1.7.4", "cors": "^2.8.5", "echarts": "^5.2.2", "ethers": "^5.5.3", "feathers-hooks-common": "^5.0.6", "feathers-memory": "^4.1.0", "feathers-mongodb": "^6.4.1", "feathers-mongoose": "^8.5.1", "feathers-profiler": "^0.1.5", "feathers-reactive": "^0.8.2", "feathers-shallow-populate": "^2.5.1", "helmet": "^4.6.0", "immer": "^9.0.7", "lodash": "^4.17.21", "luxon": "^2.3.0", "matomo-tracker": "^2.2.4", "mongodb": "^3.7.3", "mongodb-core": "^3.2.7", "mongoose": "^6.1.6", "moralis": "^1.2.4", "nedb": "^1.8.0", "ngx-echarts": "^8.0.1", "node-schedule": "^2.1.0", "path": "^0.12.7", "puppeteer": "^11.0.0", "rss-parser": "^3.12.0", "rxjs": "~6.6.0", "serialize-error": "^8.1.0", "tslib": "^2.0.0", "winston": "^3.4.0", "winston-daily-rotate-file": "^4.5.5", "zone.js": "0.11.4"
Server
0.0.340
Client
^1.2.4
Linux
Not applicable
Logs