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

New Website Initialization Fails, Missing package.json #6

Open
ma2t opened this issue Oct 17, 2023 · 10 comments
Open

New Website Initialization Fails, Missing package.json #6

ma2t opened this issue Oct 17, 2023 · 10 comments

Comments

@ma2t
Copy link
Contributor

ma2t commented Oct 17, 2023

First off, thank you for creating such an innovative project; the concept is fantastic!
I've run into an issue while trying to initialize a new website, and I was hoping you could help me resolve it.

I tried to create a new website using the static new test-website command. The process failed with an error stating that package.json is missing in the directory. Only a package-lock.json and a starter-main folder were generated.
Steps to Reproduce:

  • Run static new test-website
  • Observe the error regarding missing package.json

Expected Behavior:

A new website should be initialized with all the required files, including package.json.
Actual Behavior:

The test-website folder was created, but it only contains:

  • package-lock.json
  • starter-main folder

Error Log:

Error building assets, please re-run static dev command.
Error: Command failed: cd /home/matt/test-website && npm install && static build
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/matt/test-website/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/matt/test-website/package.json'
...

Environment:

  • Node version: v18.18.0
  • npm version: 9.8.1
@tnylea
Copy link
Contributor

tnylea commented Oct 18, 2023

Hey Matt 👋

Thanks for letting me know the issue you are having. Let's work to resolve the issue.

Are you on a PC or a Mac?

You could also try cloning this into a new folder: https://github.com/static-templates/starter and then running static dev.

Let me know if that works and which operating system you are on.

If you run this again in a different folder do you get the same output.

Let me know :)

Talk to you soon!

@ma2t
Copy link
Contributor Author

ma2t commented Oct 20, 2023

Hello!

Thanks for your reply!

I'm on a PC and have conducted this test on a minimal Ubuntu VM. I can grant
you access if needed :)

I believe the issue lies in the path where the command fails.

Here's the folder content:

$ ls -l /home/matt/test-website/
total 8
-rw-rw-r--  1 matt matt   84 Oct 20 23:41 package-lock.json
drwxrwxr-x 10 matt matt 4096 Oct 20 23:41 starter-main

If I use the following command instead:

$ cd /home/matt/test-website/starter-main && npm install && static build
[...]
Successfully built your new static website 🤘

Thank you for your time and assistance 👍

@kleczekr
Copy link

Hey! I wanted to up this issue; am facing the same when running Static from WSL on Windows.

@tnylea
Copy link
Contributor

tnylea commented Oct 25, 2023

Hey @ma2t,

Yes that would be great if you could grant me access to the Ubuntu VM. So, I've just tested it using Parallels on my Mac and everything went fine, but of course a Windows emulator vs. Windows machine are probably setup a little different.

So, this line number 47, inside of src/new.js:

mv(process.cwd() + '/' + repoName + '-main', process.cwd(), {mkdirp: false, clobber: false}, function(err) {```

Is supposed to move the contents from this folder /home/matt/test-website/starter-main/ into the folder name you specified: /home/matt/test-website/, but it doesn't look like that's happening.

The error that you are getting happens after this is supposed to run which is why it's giving you that error.

Can you give me the full output that you see before this error, I want to see which step it got to in your case. Here's the output I got when running on a Windows Parallels machine:

C:\Users\tonylea>static new coolsite
New setup initialized
Downloading starter template
Finished downloading template
Extracting template zip file
Finished unzipping
New site available inside coolsite folder
processing template builds and starting dev server
Server running at http://localhost:3000

However, this is all worked, so all the output was displayed correctly. If you could get me access to that VM it would make it easier for me to debug and find out what's going on 😉

@kleczekr Thanks for letting me know. I'll try and get this resolved 😊

Super appreciate it! Talk to you guys soon.

@psion-ar
Copy link

First things first.
Thank you for this amazing piece of software <3

I am having the same issue.
I run manjaro linux on my machine.

This is the output after running static new test:

New setup initialized
Downloading starter template
Finished downloading template
Extracting template zip file
Finished unzipping
New site available inside test folder
processing template builds and starting dev server
Error building assets, please re-run static dev command.
Error: Command failed: cd /home/ar/temp/test && npm install && static build
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/ar/temp/test/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/ar/temp/test/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in: /home/ar/.npm/_logs/2023-10-25T17_43_24_704Z-debug-0.log

    at ChildProcess.exithandler (node:child_process:422:12)
    at ChildProcess.emit (node:events:515:28)
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5) {
  code: 254,
  killed: false,
  signal: null,
  cmd: 'cd /home/ar/temp/test && npm install && static build'
}
Server running at http://localhost:3000

Just wanna let you know.
Thank you for your efforts and your time.

Regards, Alex

@ma2t
Copy link
Contributor Author

ma2t commented Oct 28, 2023

Hi @tnylea,

I added the following after line 47:

    if (err) {
        console.error('Failed to move files:', err);
        return;
    }

Here is what I got:

    Failed to move files: [Error: EEXIST: file already exists, link '/home/tnylea/test/starter-main' -> '/home/tnylea/test'] {
  errno: -17,
  code: 'EEXIST',
  syscall: 'link',
  path: '/home/tnylea/test/starter-main',
  dest: '/home/tnylea/test'
}

You can try it on [email protected].
I set-up your SSH key, the file is into /usr/lib/node_modules/@devdojo/static/src/new.js
and you can use sudo (don't be evil ;)).

I've submitted a pull request #11 with some suggested fixes.
Specifically, instead of decompressing the template into a separate folder and then moving its content,
the updated code directly decompresses the template content into the target folder.
Let me know what do you think about this idea.

Additionally, I've added a try/catch block when the script attempts to open the URL in the browser.
This should help handle scenarios where the code is running on systems without a GUI, preventing crashes.

Sincerely;

@tnylea
Copy link
Contributor

tnylea commented Nov 2, 2023

@ma2t That's great. I think you're right that it probably would be best to decompress it exactly into the target folder.

I'm going to do some testing and make sure this works with all the templates and then I'll probably get this merged within a day or two 👏

Thanks a ton!

@ma2t
Copy link
Contributor Author

ma2t commented Nov 2, 2023

A small adjustment to your test will surely be necessary.
Thanks to you 🚀

@tnylea
Copy link
Contributor

tnylea commented Nov 14, 2023

@ma2t would you mind re-opening another pull request with this fix. I'll have to re-visit in the next few days. I merged in and then tested out the unzipping functionality but it did not work correctly.

If you can re-open I'll revisit in a few days. Thanks man!

@gide0n
Copy link

gide0n commented May 14, 2024

Hi @tnylea!
First, thanks for this software, I really like it! ;)

One thing, is this problem solved?
I was creating a new project and again this issue showed.

Please, could you tell anything?
Thanks in advance!

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

5 participants