Trying to use a specific version of a node module (v0.2.0) in my own project, but one of my dependencies requires v0.1.8 of the same module. No issue, I thought, that dependency will use v0.1.8 in its nested node_modules folder and my app will use v0.2.0 in my project's node_modules folder. I added v0.2.0 as a dependency to my package.json and ran npm install again. However, for some reason my app points to the other dependency's v0.1.8 module (in its nested node_modules) when I ctrl-click it, instead of the expected v0.2.0 module correctly installed in the project's own node_modules folder. Here's the code I'm using to import from the modules (#metaplex/js relies on v0.1.8 of #solana/spl-token, while I need to use v0.2.0 of #solana/spl-token in my own app):
import { ... } from "#solana/spl-token";
import { ... } from '#metaplex/js';
I verified that the v0.1.8 spl-token was installed in ./node_modules/#metaplex/js/node_modules/#solana/spl-token, and the v0.2.0 spl-token was installed in ./node_modules/#solana/spl-token. I also ran npm ls #solana/spl-token to make sure it was in the dependency tree, and here are the results:
├─┬ #metaplex-foundation/mpl-token-metadata#1.2.5
│ └── #solana/spl-token#0.1.8
├─┬ #metaplex/js#4.12.0
│ ├─┬ #metaplex-foundation/mpl-auction#0.0.2
│ │ └── #solana/spl-token#0.1.8
│ ├─┬ #metaplex-foundation/mpl-metaplex#0.0.5
│ │ ├─┬ #metaplex-foundation/mpl-token-metadata#0.0.2
│ │ │ └── #solana/spl-token#0.1.8 deduped
│ │ └── #solana/spl-token#0.1.8
│ ├─┬ #metaplex-foundation/mpl-token-vault#0.0.2
│ │ └── #solana/spl-token#0.1.8
│ └── #solana/spl-token#0.1.8
└── #solana/spl-token#0.2.0
I can't figure out why my code still imports from the wrong version used by another dependency when I installed the correct version in my project's node_modules folder. Is there a workaround or solution to solve this?
fairly new to node, sorry
Edit: (my project is a typescript react project) did some more poking around and apparently, v0.1.8 of the module's package.json's types property points to an *.d.ts file like this:
declare module '#solana/spl-token' {
export //functions, fields, etc
}
while v0.2.0's package.json's types property points to a simple *.d.ts file like
export * from './instructions/index';
...
(note there is no specific declare keyword for the module itself)
and each function has a separate *.d.ts where the specific member is declared, as such in functionName.d.ts:
export declare function functionName(...): Promise<...>;
I don't know if this change causes some type of namespace conflict but it seems like this is a very specific error having to do with this particular module and not something generally wrong with node.
What do you mean by very specific error ?
This Is very common issue
At yow tsconfig.json set the baseUrl AND paths
{
...
"baseUrl":"./node_modules",
"paths":{
"name-of-the-package":[
"relative-to-baseurl/position/where/yow-code-is"
]
}}
The position of yow code Is relative to baseUrl.
Related
I am developing a code for my school's rocketry team and I have two programs, one meant to flash the on-board computer and another to run some data analysis on the flight data. The chip code uses no_std while the data analysis program uses std. The data-analysis code will run on my PC, and the chip code will run on the chip.
Here is my workspace root Cargo.toml and my project graph:
[workspace]
members = [
"chip",
"data-analysis",
]
.
├── Cargo.lock
├── Cargo.toml
├── chip
│ ├── Cargo.toml
│ ├── memory.x
│ ├── openocd.cfg
│ ├── openocd.gdb
│ └── src
│ └── main.rs
├── data-analysis
│ ├── Cargo.toml
│ └── src
│ └── main.rs
├── README.md
└── resources
├── 3m.mkd
├── data-stm32f103c8t6.pdf
├── links.txt
├── reference-stm32f103xx.pdf
├── schematic-stm32f103c8t6.png
└── todo.txt
I have decided to use a workspace to organize my code. When I attempt to build the workspace, I get the error:
error[E0463]: can't find crate for `std`
|
= note: the `thumbv7m-none-eabi` target may not support the standard library
= note: `std` is required by `data_analysis` because it does not declare `#![no_std]`
= help: consider building the standard library from source with `cargo build -Zbuild-std`
When I compile with cargo build -Zbuild-std I get the error:
error[E0463]: can't find crate for `panic_abort`
error[E0658]: use of unstable library feature 'restricted_std'
|
= help: add `#![feature(restricted_std)]` to the crate attributes to enable
However I need no_std and not restricted_std.
I understand that dependencies for all files are stored in Cargo.lock and presumably that's why it is producing this error. My question is, how do I express to the compiler that I need std for data_analysis but not for chip code? Should I even be using workspaces over just using one package with multiple binaries and using [features] in the Cargo.toml?
It seems like you're trying to complile data_analysis with the same target as chip. I recommend just getting rid of the root Cargo.toml and compiling the respective ones in the folders. You could make a Makefile to automate this easily
So my folder structure is like this
.
├── eulerlibs
│ ├── EulerLibs
│ └── eulerlibs.cabal
├── flake.lock
├── flake.nix
├── p001
│ ├── Main.hs
│ └── p001.cabal
├── p002
│ ├── Main.hs
│ └── p002.cabal
├── p003
│ ├── Main.hs
│ └── p003.cabal
├── p004
│ ├── Main.hs
│ └── p004.cabal
├── p005
│ ├── Main.hs
│ └── p005.cabal
What I am trying to do is import the library modules in the ./eulerlibs (library) cabal directory to lets say ./p005(executable) cabal directory
I do understand that I can include built libraries (*.so), but can find no way of linking two cabal projects
I'm very new to cabal as well as haskell so some insight will be much appreciated. If nothing works out I'll have to add the library to p005 itself which I really want to avoid.
You can do this with a cabal.project file. Place it at the top level (in the . directory) with these contents:
packages: */*.cabal
Then you will be able to use all those libraries in each other's cabal files in the build-dependencies, e.g. in p001.cabal:
...
library
...
build-depends: base, eulerlibs
...
...
Here is the full documentation of cabal.project files: https://cabal.readthedocs.io/en/latest/cabal-project.html
I have one shared library and one header file.
I did one sample project there I have generated .so and header files but now my problem is how to import existing .so and .h files in android studio.
I searched in google but there they are showing how to generate but I want how to import these files. Please suggest me some links or any other examples
but now my problem is how to import existing .so and .h files in android studio
Usually, you should put your .so files inside jniLibs which is usually located at app/src/main/jniLibs, and put c/c++ source code inside app/src/main/cpp. See below directory structure.
.
├── CMakeLists.txt // Your cmake configuration files.
├── app.iml
├── build
├── build.gradle
├── libs
├── proguard-rules.pro
└── src
├── androidTest
│ └── java
├── main
│ ├── AndroidManifest.xml
│ ├── cpp // Directory to put your jni native source code.
│ │ └── native-lib.cpp
│ ├── java
│ ├── jniLibs // Directory to put your jni libs, i.e. the .so files.
│ └── res
└── test
└── java
See: https://stackoverflow.com/a/52048933/8034839
The directory layout of a Rust project should look like this (source)
.
├── Cargo.lock
├── Cargo.toml
├── benches
│ └── large-input.rs
├── examples
│ └── simple.rs
├── src
│ ├── bin
│ │ └── another_executable.rs
│ ├── lib.rs
│ └── main.rs
└── tests
└── some-integration-tests.rs
What is the file simple.rs under examples? How do I execute it? How should the file look like?
Examples are useful in library crates to show how the crate is used.
An example can be an executable with a main method or a library; it can either be in a single file examples/example-name.rs or consist of several files in a subdirectory examples/example-name/, with the main method in main.rs. To compile a library example you need to specify its crate type in Cargo.toml:
[[example]]
name = "example-name"
crate-type = ["lib"]
Examples are compiled by cargo test to ensure that they are up to date with the crate. You can run a specific executable example by
cargo run --example <example-name>
and selectively build any example with
cargo build --example <example-name>
This is documented in the Cargo Reference.
Where should one put the sources, examples, documentation, unit tests, integration tests, license, benchmarks etc?
Cargo, the official package manager for Rust, defines some conventions regarding the layout of a Rust crate:
.
├── Cargo.lock
├── Cargo.toml
├── benches
│ └── large-input.rs
├── examples
│ └── simple.rs
├── src
│ ├── bin
│ │ └── another_executable.rs
│ ├── lib.rs
│ └── main.rs
└── tests
└── some-integration-tests.rs
Cargo.toml and Cargo.lock are stored in the root of your project.
Source code goes in the src directory.
The default library file is src/lib.rs.
The default executable file is src/main.rs.
Other executables can be placed in src/bin/*.rs.
Integration tests go in the tests directory (unit tests go in each file they're testing).
Example executable files go in the examples directory.
Benchmarks go in the benches directory.
These are explained in more detail in the manifest description.
By following this standard layout, you'll be able to use Cargo's commands to build, run and test your project easily. Run cargo new to set up a new executable project or cargo new --lib to set up a new library project.
Additionally, documentation for libraries is often written in documentation comments (comments that start with /// before any item, or //! to document the parent item). Also, the license is usually put at the root.
Unit tests, as mentioned above, are written in the same module as the functions they're testing. Usually, they're put in an inner module. It looks like this (this is what Cargo generates for a new library with cargo new --lib):
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
}
}