nandorojo / solito

🧍‍♂️ React Native + Next.js, unified.
https://solito.dev
MIT License
3.54k stars 180 forks source link

Error when running create-solito-app #11

Closed dannyhw closed 2 years ago

dannyhw commented 2 years ago

Hey I love this, great work!

As mentioned on twitter I got an error running create-solito-app. Setting up with vercel got me a 404 though that could easily be a me problem since I've not used it before.

npx create-solito-app@latest my-solito-app
npx: installed 82 in 10.733s
yarn run v1.23.0-20211220.1904
error Couldn't find a package.json file in "/Users/danny/workspace/solito"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Command failed: yarn ts-node index.ts

running

macos 12.2.1
node v14.19.0
yarn 1.23.0-20211220.1904

let me know if you need any more details.

nandorojo commented 2 years ago

should be fixed with https://github.com/nandorojo/solito/commit/d39d3b3608cabfa2a31a02b208c21f1e99e8ccf1

thanks for finding that!

dannyhw commented 2 years ago

No worries thanks for the quick response! Trying it now :)

dannyhw commented 2 years ago

@nandorojo getting a different error 😅


[solito] Failed to download example

 Error: Cannot find module '/Users/danny/.npm/_npx/21214/lib/node_modules/create-solito-app/dist/package.json'
    at webpackContextResolve (/Users/danny/.npm/_npx/21214/lib/node_modules/create-solito-app/dist/index.js:34:22233)
    at webpackContext (/Users/danny/.npm/_npx/21214/lib/node_modules/create-solito-app/dist/index.js:34:22142)
    at run (/Users/danny/.npm/_npx/21214/lib/node_modules/create-solito-app/dist/index.js:34:334281)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  code: 'MODULE_NOT_FOUND'
}
nandorojo commented 2 years ago

ah yeah I see the issue.

I'm not a node CLI developer often, so I forget that running the CLI from npx isn't the same as on my computer lol.

I think I am pushing a fix now

nandorojo commented 2 years ago

FWIW, even though it errors, it actually is working. it's just failing to edit your package.json with the proper name.

I'm not sure how to solve this. I'm using process.cwd() to get the current place where the user is located, but that doesn't seem to be working.

dannyhw commented 2 years ago

ah I see so this require is throwing the exception?

const pkg = require(path.resolve(
      process.cwd(),
      resolvedProjectPath,
      'package.json'
    ))

or the write after that

I could try some stuff locally if that's helpful

nandorojo commented 2 years ago

yeah that's the line. I'm playing with it now too. it seems to keep reading from .npx instead of cwd. i'm going to try printing some stuff out to see what's up

nandorojo commented 2 years ago

maybe path.resolve is unnecessary there since it's already resolved? hm

dannyhw commented 2 years ago

well I think even if it is usually resolve is pretty smart and can remove extra things. Seems possible that npx might change the way process.cwd works though. There is probably a good example of this I can check in the storybook repo.

nandorojo commented 2 years ago
Screen Shot 2022-03-14 at 6 54 48 PM

I'm going a bit crazy here. Shouldn't these log the same things, but one of them just has package.json appended to it? Because they're logging totally different things. resolvedPackagePath is correct, and somehow pkgPath is giving me something in the wrong directory

dannyhw commented 2 years ago

Ah ok well I guess path.resolve tries to be clever since it wants to resolve a absolute path, you can use join to just put them together.

if the project path is already resolved its probably safe to just do path.join

nandorojo commented 2 years ago

right...I tried join as well, weirdly that gives me the same error.

something feels so off. this code:

    console.log('[solito] resolved path :', resolvedProjectPath)
    const pkgPath = resolvedProjectPath + '/package.json'
    console.log('[solito] package.json path:', pkgPath)

Results in this error:

[solito] resolved path : /path-to/create-solito-app/create-test-app
[solito] package.json path: /path-to/create-solito-app/dist/package.json

I replaced my actual paths with path-to. How can this make any sense?

nandorojo commented 2 years ago

If I do this:

    const pkgPath = `${resolvedProjectPath}/package.json`

It gives the wrong path. But if I take out /package.json at the end, it gives the right one. It's as if the variable is getting hoisted early and cached or something.

nandorojo commented 2 years ago

Yeah that's gotta be it. When I use ts-node it seems to work.

dannyhw commented 2 years ago

wow this is really weird, is there a chance it could be related to the spawning of a child process?

not really encountered this kind of thing before, no idea why it would just randomly change like that 😅

dannyhw commented 2 years ago

if you emit js from tsc and run that instead of using ts-node does it work?

nandorojo commented 2 years ago

I'll try that too. Have to go to dinner so I'm going to publish this without the editing of package.json for now so it doesn't have any substantial errors. Who knew CLI and FS was so complicated lol

nandorojo commented 2 years ago

Okay so it works for me now.

The only weird thing left is, when I deploy to Vercel, it doesn't work, but building locally does work. 🧐

nandorojo commented 2 years ago

fixed