Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[create] place .npmrc in the correct place if creating app within existing pnpm monorepo #239

Open
prabirshrestha opened this issue Nov 16, 2024 · 1 comment

Comments

@prabirshrestha
Copy link

prabirshrestha commented Nov 16, 2024

I was trying to integrate onestack to an existing monorepo but it doesn't compile correctly. At first I thought it could be due to conflicts with my existing monorepo but even an empty one doesn't seem to work.

Repro steps:

  1. Create brand new folder monorepo and run git init.
  2. Add package.json
{
  "name": "monorepo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
  1. Create a pnpm-workspace.yaml file.
packages:
  - "./apps/**"
  1. mkdir apps.
  2. cd apps
  3. create an onestack project called app via pnpx one@latest and use minimal tamagui app with pnpm as package manager.
  4. Go to do the root cd .. and add gitignore file with the following content.
node_modules/
  1. run git add -A and commit the initial empty onestack app.
  2. run git clean -xdf :/ from the root to remove all untracked files.
  3. run pnpm install from the root.
  4. from root run the the app via pnpm --filter app dev. You will see the following error
Error
pnpm --filter app dev

> [email protected] dev /Users/prabirshrestha/code/tmp/monorepo/apps/app
> one dev

✘ [ERROR] Could not resolve "@tamagui/shorthands/v2"

    config/tamagui/tamagui.config.ts:2:27:
      2 │ import { shorthands } from '@tamagui/shorthands/v2'
        ╵                            ~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@tamagui/shorthands/v2" as external to exclude it from the bundle, which
  will remove this error and leave the unresolved path in the bundle.

✘ [ERROR] Could not resolve "@tamagui/animations-css"

    config/tamagui/animations.ts:1:33:
      1 │ import { createAnimations } from '@tamagui/animations-css'
        ╵                                  ~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@tamagui/animations-css" as external to exclude it from the bundle, which
  will remove this error and leave the unresolved path in the bundle.

Error bundling tamagui config: Build failed with 2 errors:
config/tamagui/animations.ts:1:33: ERROR: Could not resolve "@tamagui/animations-css"
config/tamagui/tamagui.config.ts:2:27: ERROR: Could not resolve "@tamagui/shorthands/v2" (run with DEBUG=tamagui to see stack)
No bundled config generated, maybe an error in bundling. Set DEBUG=tamagui and re-run to get logs.
[vite] connected.
11:59:41 PM [vite] (ssr) warning: rewrote react-native-safe-area-context to @vxrn/safe-area but was not an abolute path and was not handled by other plugins. This will lead to duplicated modules for the same path. To avoid duplicating modules, you should resolve to an absolute path.
  Plugin: alias
Cannot optimize dependency: react-native-safe-area-context, present in ssr 'optimizeDeps.include'
Error: The following dependencies are imported but could not be resolved:

  @tamagui/shorthands/v2 (imported by /Users/prabirshrestha/code/tmp/monorepo/apps/app/config/tamagui/tamagui.config.ts)
  @tamagui/animations-css (imported by /Users/prabirshrestha/code/tmp/monorepo/apps/app/config/tamagui/animations.ts)

Are they installed?
    at file:///Users/prabirshrestha/code/tmp/monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/dep-BZ_CwQkz.js:37640:15
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async file:///Users/prabirshrestha/code/tmp/monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/dep-BZ_CwQkz.js:66107:28
11:59:41 PM [vite] (ssr) warning: rewrote react-native-safe-area-context to @vxrn/safe-area but was not an abolute path and was not handled by other plugins. This will lead to duplicated modules for the same path. To avoid duplicating modules, you should resolve to an absolute path.
  Plugin: alias
✘ [ERROR] Could not read from file: /Users/prabirshrestha/code/tmp/monorepo/apps/app/@vxrn/safe-area

    ../../node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected][email protected]_@babel+c_63bszf4fyn7ejgs7ng7ki2xwkq/node_modules/one/dist/esm/index.mjs:10:29:
      10 │ import { SafeAreaView } from "react-native-safe-area-context";
         ╵                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

11:59:42 PM [vite] (ssr) warning: rewrote react-native-safe-area-context to @vxrn/safe-area but was not an abolute path and was not handled by other plugins. This will lead to duplicated modules for the same path. To avoid duplicating modules, you should resolve to an absolute path.
  Plugin: alias
11:59:42 PM [vite] (ssr) warning: rewrote react-native-safe-area-context to @vxrn/safe-area but was not an abolute path and was not handled by other plugins. This will lead to duplicated modules for the same path. To avoid duplicating modules, you should resolve to an absolute path.
  Plugin: alias
11:59:42 PM [vite] (ssr) warning: rewrote react-native-safe-area-context to @vxrn/safe-area but was not an abolute path and was not handled by other plugins. This will lead to duplicated modules for the same path. To avoid duplicating modules, you should resolve to an absolute path.
  Plugin: alias
11:59:42 PM [vite] (ssr) warning: rewrote react-native-safe-area-context to @vxrn/safe-area but was not an abolute path and was not handled by other plugins. This will lead to duplicated modules for the same path. To avoid duplicating modules, you should resolve to an absolute path.
  Plugin: alias
11:59:42 PM [vite] (ssr) warning: rewrote react-native-safe-area-context to @vxrn/safe-area but was not an abolute path and was not handled by other plugins. This will lead to duplicated modules for the same path. To avoid duplicating modules, you should resolve to an absolute path.
  Plugin: alias
11:59:42 PM [vite] (ssr) warning: rewrote react-native-safe-area-context to @vxrn/safe-area but was not an abolute path and was not handled by other plugins. This will lead to duplicated modules for the same path. To avoid duplicating modules, you should resolve to an absolute path.
  Plugin: alias
11:59:42 PM [vite] (ssr) warning: rewrote react-native-safe-area-context to @vxrn/safe-area but was not an abolute path and was not handled by other plugins. This will lead to duplicated modules for the same path. To avoid duplicating modules, you should resolve to an absolute path.
  Plugin: alias

 ERROR  Build failed with 1 error:                                                                                                            11:59:42 PM
../../node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected][email protected]_@babel+c_63bszf4fyn7ejgs7ng7ki2xwkq/node_modules/one/dist/esm/index.mjs:10:29: ERROR: Could not read from file: /Users/prabirshrestha/code/tmp/monorepo/apps/app/@vxrn/safe-area

  ../../node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected][email protected]_@babel+c_63bszf4fyn7ejgs7ng7ki2xwkq/node_modules/one/dist/esm/index.mjs:10:29: ERROR: Could not read from file: @vxrn/safe-area
  at failureErrorWithLog (/Users/prabirshrestha/code/tmp/monorepo/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1472:15)
  at /Users/prabirshrestha/code/tmp/monorepo/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:945:25
  at /Users/prabirshrestha/code/tmp/monorepo/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1353:9
  at process.processTicksAndRejections (node:internal/process/task_queues:105:5)



 ERROR  Build failed with 1 error:                                                                                                            11:59:42 PM
../../node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected][email protected]_@babel+c_63bszf4fyn7ejgs7ng7ki2xwkq/node_modules/one/dist/esm/index.mjs:10:29: ERROR: Could not read from file: /Users/prabirshrestha/code/tmp/monorepo/apps/app/@vxrn/safe-area

/Users/prabirshrestha/code/tmp/monorepo/apps/app:
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  [email protected] dev: `one dev`
Exit status 1
Packages are installed in the app folder
prabirshrestha@Mac ~/c/t/m/a/app (main)> pwd
/Users/prabirshrestha/code/tmp/monorepo/apps/app
prabirshrestha@Mac ~/c/t/m/a/app (main)> ls node_modules/
@biomejs/                       expo@                           react-native-reanimated@        tamagui@
@react-native-masked-view/      expo-modules-core@              react-native-safe-area-context@ vite@
@tamagui/                       one@                            react-native-screens@
@types/                         react@                          react-native-svg@
@vxrn/                          react-native@                   react-native-web@
@prabirshrestha
Copy link
Author

Finally found the root cause. Seems like it does create .nmprc with node-linker=hoisted but at apps/app/.npmrc instead of the root besides pnpm-workspace.yaml. Moving .npmrc file worked.

pnpx one@latest should be smart to detect this and create .npmrc file in the appropriate place.

@zetavg zetavg changed the title one doesn't work on an existing monorepo [create] place .npmrc in the correct place if creating app within existing pnpm monorepo Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant