Open AGallouin opened 1 year ago
Hey @AGallouin, how do the package is being imported? which typescript version are you using? Could you check if you have the same issue with 5.3.0?
Issue closed due inactivity. Please, open again the issue if the error persists and you have more evidences.
@bigmontz what timing haha - I am looking at this issue right now as I am also facing this error.
@bigmontz for me I've reproduced the issue on 5.14, 5.13, and 5.3.0 since it's mentioned above. I am using typescript@5.2.2 in a pnpm workspace. My usage is like so:
// neo4j.ts
import neo4j from "neo4j-driver";
const { NEO4J_URI, NEO4J_AUTH_USERNAME, NEO4J_AUTH_PASSWORD } = process.env;
if (!NEO4J_URI || !NEO4J_AUTH_USERNAME || !NEO4J_AUTH_PASSWORD) {
throw Error("Missing Neo4j environment variables");
}
export default neo4j.driver(
NEO4J_URI,
neo4j.auth.basic(NEO4J_AUTH_USERNAME, NEO4J_AUTH_PASSWORD)
);
// index.ts
import neo4j from "./neo4j";
import { Draft, Node, Relationship } from "./types";
export default neo4j;
export async function create<T extends keyof Node>(
label: T,
properties: Draft<Node[T]>
) {
const session = neo4j.session();
const res = await session.run<Node[T]>(
`...Cypher query...`,
{ label, ...properties }
);
return res;
}
The declaration of the create
function triggers the following error:
The inferred type of 'create' cannot be named without a reference to '.pnpm/neo4j-driver-core@5.14.0/node_modules/neo4j-driver-core/types/result'. This is likely not portable. A type annotation is necessary.
For anyone in need of an interim solution: it's regrettable, but explicitly installing neo4j-driver-core
and adding the following import resolves the issue for me:
import "neo4j-driver-core";
Can you share your tsconfig file?
I had configured a project like this, npm run build
works fine.
// tsconfig.json
{
"compilerOptions": {
"target": "ES5",
"lib": ["ES6", "es2015"],
"noImplicitAny": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"esModuleInterop": true,
"moduleResolution": "node",
"downlevelIteration": true,
"outDir": "lib",
"declaration": true,
"declarationDir": "types",
"isolatedModules": true,
"types": ["node"]
},
"include": [
"index.ts"
]
}
// package.json
{
"name": "github1053",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc -p tsconfig.json"
},
"author": "",
"license": "ISC",
"dependencies": {
"neo4j-driver": "^5.14.0"
},
"devDependencies": {
"@types/node": "^20.8.9",
"typescript": "^5.2.2"
}
}
// index.ts
import { RecordShape } from "neo4j-driver";
import neo4j from "./neo4j";
export default neo4j;
export async function create<Shape extends RecordShape = RecordShape>(
label: string,
properties: any
) {
const session = neo4j.session();
const res = await session.run<Shape>(
`...Cypher query...`,
{ label, ...properties }
);
return res;
}
// neo4j.ts
import neo4j from "neo4j-driver";
// @ts-ignore
const { NEO4J_URI, NEO4J_AUTH_USERNAME, NEO4J_AUTH_PASSWORD } = process.env;
if (!NEO4J_URI || !NEO4J_AUTH_USERNAME || !NEO4J_AUTH_PASSWORD) {
throw Error("Missing Neo4j environment variables");
}
export default neo4j.driver(
NEO4J_URI,
neo4j.auth.basic(NEO4J_AUTH_USERNAME, NEO4J_AUTH_PASSWORD)
);
@dylanjt Can you share your tsconfig?
Hello,
When bumping neo4j-driver package from 4.4.2 to 5.4.0, I'm having issues with the base types of neo4j (Integer, Record, Session etc.). All my neo4j connections are made using a facade package around neo4j-driver, and exposing basic methods and aliases to the types mentioned above to the rest of the codebase. Everytime typescript needs to infer a return type that includes one of thoses types, I have an error like this one.
The only simple solution i found until now is to add directly the package neo4j-driver-core as a dependency of my package even though the readme explicitly tells me otherwise.
Dependency schema if unclear:
I don't even understand why does this error means exactly, do you have any insights on it ?