You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm sorry if my problem is too silly. I've only been using Rust for a short time and I'm still having beginner problems.
I encountered an issue when creating a new project with neon using the following steps:
Created a new neon project with the command:
npm init neon test
Selected "app" option on prompt
Updated Cargo.toml to set a custom path for rust files:
[lib]
path = "lib/lib.rs"
Added a new index.ts file under the src directory.
Build using npm run cargo-build -- --release which executes cargo build --message-format=json > cargo.log. I also tried with cargo-cp-artifact -nc lib.node -- cargo build --message-format=json-render-diagnostics.
Tried to import the .node file in index.ts like this:
importlibfrom'../index.node';
However, when running the code, I received the following error:
Cannot find module '../index.node' or its corresponding type declarations.
It seems that the module resolution is failing to locate the .node file. Could this be related to the change in the lib path within Cargo.toml, or is there a step missing in the build process when using a custom library path?
Expected Behavior:
The index.node file should be correctly found and imported without throwing a module resolution error.
Environment:
Node.js version: 20.16.0
@neon-rs/cli version: 0.1.73
Neon Version: 1
Cargo version: 1.81.0
Operating System: Ubuntu 20.04.6 LTS
The text was updated successfully, but these errors were encountered:
I don't think it's related to moving the Rust source. Could it be the TypeScript config not understanding native modules or resolving to the wrong place? Does it work with vanilla JS?
@bruno-sartori Your error is pined up to difference between CommonJS (common node.js) syntax and ES Modulessyntax, describes how elements to be called wihin your project. Among that strongly associated with TypeScript Type awareness.
**I've made for you and everybody with same error repository contains solution guideline: https://github.com/kotekpsotek/napi-ts-example
When you've another trouble, feel free to ask here or as repo issue 👍
@kjvalencik As you've said this is not directly related to Neon_Bindings but to interactions from TypeScript project, nonetheless the Neon_Bindings should include examples covering such cases, TypeScript is industrial match.
Yes, this is related to Es-Modules syntax doesn't understad the files with .node extension ... so we must play trick with her.
VanillaJs in terms of Node.js uses CommonJS require() syntax which understands perfectly .node files purpose, but you still stay without hinters for your code editor what is inside
I'm sorry if my problem is too silly. I've only been using Rust for a short time and I'm still having beginner problems.
I encountered an issue when creating a new project with
neon
using the following steps:Created a new neon project with the command:
npm init neon test
Selected "app" option on prompt
Updated
Cargo.toml
to set a custom path for rust files:Added a new
index.ts
file under thesrc
directory.Build using
npm run cargo-build -- --release
which executescargo build --message-format=json > cargo.log
. I also tried withcargo-cp-artifact -nc lib.node -- cargo build --message-format=json-render-diagnostics
.Tried to import the
.node
file inindex.ts
like this:However, when running the code, I received the following error:
It seems that the module resolution is failing to locate the
.node
file. Could this be related to the change in thelib
path withinCargo.toml
, or is there a step missing in the build process when using a custom library path?Expected Behavior:
The
index.node
file should be correctly found and imported without throwing a module resolution error.Environment:
The text was updated successfully, but these errors were encountered: