Repository: nodejs/help

Issue #4104: Node cannot find peer dependency of locally installed modules
Created: 2023-02-20T02:33:36Z
Details
I'm locally developing some modules.  I have both modules building correctly.
linql.core
linql.client
In my node app, when I import linql.client and attempt to use it, node throws the following:
//Uncaught Error Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'linql.core' imported from Typescript\dist\linql.client\fesm2015\linql.client.mjs
When I try and use linql.client directly though, it has no issue finding the module.
I've tried the following with no luck:
"--experimental-modules",
"--experimental-specifier-resolution=node",
"--es-module-specifier-resolution=node"

Any help is much appreciated, as I've spent quite some time trying to figure this one out.
Node.js version
node --version
v16.16.0
Example code
Clone this git repository: https://github.com/KrisSodroski/NodeImportExample
In the root of the project:
npm i
npm run setupcore
npm run setupclient
Navigate to examples/node
run the following:
npm i
npx tsc 
node ./dist/main.js
You will get this error:
//Uncaught Error Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'linql.core' imported from ...\Typescript\dist\linql.client\fesm2015\linql.client.mjs
Now modify app.ts as so (linql.client is completely removed from the imports):
//import { DataModelClient } from "linql.client";
import { CoreModel } from "linql.core";

class LinqlNodeExample
{
    async Run()
    {

        //This doesn't work because it says it can't find linql.core
        //Uncaught Error Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'linql.core' imported from C:\testModuleImport\Typescript\dist\linql.client\fesm2015\linql.client.mjs
        // const test = new DataModelClient();
        // console.log(test);
        //This does work, so obviously it can find linql.core
        const test2 = new CoreModel();
        console.log(test2);
    }

}

export async function Main(): Promise<any>
{

    const example = new LinqlNodeExample();
    await example.Run();

}
run the following:
npm i
npx tsc 
node ./dist/main.js
Notice the app has no issue running, and has no problem finding linql.core
Operating system
Windows 10
Scope
Runtime
Module and version
Not applicable.

Duplicate issue #4111: Node cannot find peer dependency of locally installed modules
Created: 2023-02-25T15:49:11Z
Version
node --version v16.16.0
Platform
Microsoft Windows NT 10.0.20348.0 x64
Subsystem
No response
What steps will reproduce the bug?
I'm locally developing some modules.  I have both modules building correctly.
linql.core
linql.client
In my node app, when I import linql.client and attempt to use it, node throws the following:
//Uncaught Error Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'linql.core' imported from Typescript\dist\linql.client\fesm2015\linql.client.mjs
When I try and use linql.client directly though, it has no issue finding the module.
I've tried the following with no luck:
"--experimental-modules",
"--experimental-specifier-resolution=node",
"--es-module-specifier-resolution=node"

Any help is much appreciated, as I've spent quite some time trying to figure this one out.
Example code
Clone this git repository: https://github.com/KrisSodroski/NodeImportExample
In the root of the project:
npm i
npm run setupcore
npm run setupclient
Navigate to examples/node
run the following:
npm i
npx tsc 
node ./dist/main.js
You will get this error:
//Uncaught Error Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'linql.core' imported from ...\Typescript\dist\linql.client\fesm2015\linql.client.mjs
Now modify app.ts as so (linql.client is completely removed from the imports):
//import { DataModelClient } from "linql.client";
import { CoreModel } from "linql.core";

class LinqlNodeExample
{
    async Run()
    {

        //This doesn't work because it says it can't find linql.core
        //Uncaught Error Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'linql.core' imported from C:\testModuleImport\Typescript\dist\linql.client\fesm2015\linql.client.mjs
        // const test = new DataModelClient();
        // console.log(test);
        //This does work, so obviously it can find linql.core
        const test2 = new CoreModel();
        console.log(test2);
    }

}

export async function Main(): Promise<any>
{

    const example = new LinqlNodeExample();
    await example.Run();

}
run the following:
npm i
npx tsc 
node ./dist/main.js
Notice the app has no issue running, and has no problem finding linql.core
How often does it reproduce? Is there a required condition?
Its always possible to reproduce when using "file:" packages that reference one another.
What is the expected behavior?
Node should be able to find the peer dependency that is locally installed and appears in node_modules.
What do you see instead?
Node is unable to resolve the peer dependency from a locally mapped module that is itself locally mapped.
Additional information
No response

Closing comment (2023-08-28T06:38:50Z): duplicate of #4104 ; closing