remix-run / remix

Build Better Websites. Create modern, resilient user experiences with web fundamentals.
https://remix.run
MIT License
29.5k stars 2.49k forks source link

npm run dev throw "Error: Cannot find package" in local #8240

Open XYCaptain opened 10 months ago

XYCaptain commented 10 months ago

Reproduction

npm install /Users/xxx/my_wasm/out 
pm run dev

package.json:

 "my_wasm": "file:../my_wasm/out"
import React, { useEffect, useRef } from 'react';
import * as wm from "my_wasm";

const HelloWorldPage: React.FC = () => {
      useEffect(() => {
        wm.default();
      }, []);
    return (
        <div>
            <h1>Hello World!</h1>
            <header className="App-header">
            </header>
        </div>
    );
};

export default HelloWorldPage;

System Info

System:
    OS: macOS 14.2
    CPU: (12) arm64 Apple M2 Max
    Memory: 1.46 GB / 32.00 GB
    Shell: 3.2.57 - /bin/sh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - /usr/local/bin/npm
  Browsers:
    Chrome: 119.0.6045.105
    Edge: 116.0.1938.54
    Safari: 17.2
  npmPackages:
    @remix-run/dev: ^2.4.0-pre.6 => 2.4.0-pre.6 
    @remix-run/eslint-config: ^2.4.0-pre.6 => 2.4.0-pre.6 
    @remix-run/node: ^2.4.0-pre.6 => 2.4.0-pre.6 
    @remix-run/react: ^2.4.0-pre.6 => 2.4.0-pre.6 
    @remix-run/serve: ^2.4.0-pre.6 => 2.4.0-pre.6

Used Package Manager

npm

Expected Behavior

dev normal

Actual Behavior

Error: Cannot find package '/Users/test_project/node_modules/my_wasm/' imported from /Users/test_project/node_modules/build/index.js

XYCaptain commented 10 months ago

React projects are normal

davemurphysf commented 9 months ago

I'm seeing similar behavior on a symlinked package in a monorepo:

Error: Cannot find package '/Users/dave/code/mindr/mindr/node_modules/@meetmindr/constants/package.json' imported from /Users/dave/code/mindr/mindr/apps/web/build/index.js
    at legacyMainResolve (node:internal/modules/esm/resolve:205:26)
    at packageResolve (node:internal/modules/esm/resolve:831:14)
    at moduleResolve (node:internal/modules/esm/resolve:901:20)
    at defaultResolve (node:internal/modules/esm/resolve:1121:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36)
Failed running 'server.js'

I get this error with either the "vanilla" remix dev or remix dev --manual -c \"node --watch-path server.js --watch server.js\" where server.js is from the express template

ivan-kleshnin commented 7 months ago

Same issue, couldn't figure out how to properly configure a project which relies on TypeScript ESM imports from above the project root. I use https://github.com/ecyrbe/zodios with NextJS and it works fine there.

I'd be great to have a guide or example on importing reusable components or tRPC / Zodios APIs from shared folders. I tried to migrate my NextJS project to Remix and stuck there.