velsa / notehost

Free Hosting for Notion Sites!
MIT License
87 stars 8 forks source link

Error trying to init with npx #17

Closed lucasctnh closed 5 months ago

lucasctnh commented 6 months ago

Since I'm not used to npm and npx I wonder if I am doing something wrong or if there's actually an error. This is what I receive whenever I try to init

D:\Coding\portfolio-notehost>npx notehost@latest init lucasctnh.com
Need to install the following packages:
notehost@1.0.14
Ok to proceed? (y) y
file:///C:/Users/lcsco/AppData/Local/npm-cache/_npx/aafa416c13a5a17f/node_modules/notehost/dist/cli/index.js:164
  const runDir = appPath.match(/^(.*)\/[^/]+$/)[1];
                                               ^

TypeError: Cannot read properties of null (reading '1')
    at buildOriginDir (file:///C:/Users/lcsco/AppData/Local/npm-cache/_npx/aafa416c13a5a17f/node_modules/notehost/dist/cli/index.js:164:48)
    at Command.<anonymous> (file:///C:/Users/lcsco/AppData/Local/npm-cache/_npx/aafa416c13a5a17f/node_modules/notehost/dist/cli/index.js:137:23)
    at Generator.next (<anonymous>)
    at file:///C:/Users/lcsco/AppData/Local/npm-cache/_npx/aafa416c13a5a17f/node_modules/notehost/dist/cli/index.js:19:61
    at new Promise (<anonymous>)
    at __async (file:///C:/Users/lcsco/AppData/Local/npm-cache/_npx/aafa416c13a5a17f/node_modules/notehost/dist/cli/index.js:3:10)
    at Command.initRepo (file:///C:/Users/lcsco/AppData/Local/npm-cache/_npx/aafa416c13a5a17f/node_modules/notehost/dist/cli/index.js:135:10)
    at Command.listener [as _actionHandler] (C:\Users\lcsco\AppData\Local\npm-cache\_npx\aafa416c13a5a17f\node_modules\commander\lib\command.js:494:17)
    at C:\Users\lcsco\AppData\Local\npm-cache\_npx\aafa416c13a5a17f\node_modules\commander\lib\command.js:1296:65
    at Command._chainOrCall (C:\Users\lcsco\AppData\Local\npm-cache\_npx\aafa416c13a5a17f\node_modules\commander\lib\command.js:1193:12)

Node.js v18.17.1
lucasctnh commented 6 months ago

Ok, so just to add more information. I checked the code and the problem was that appPath in the buildOriginDir function had a regex match call which wasn't matching the dir path.

By removing the regex I've encountered another problem, the buildOriginDir was returning a wrong path and the code could not find the templates folder. Here's the error:

node:fs:1527
  handleErrorFromBinding(ctx);
  ^

Error: ENOENT: no such file or directory, scandir 'D:\Coding\portfolio-notehost\node_modules\notehost\dist\cli\notehost\templates'
    at Object.readdirSync (node:fs:1527:3)
    at Command.<anonymous> (file:///D:/Coding/portfolio-notehost/node_modules/notehost/dist/cli/index.js:139:27)
    at Generator.next (<anonymous>)
    at fulfilled (file:///D:/Coding/portfolio-notehost/node_modules/notehost/dist/cli/index.js:6:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errno: -4058,
  syscall: 'scandir',
  code: 'ENOENT',
  path: 'D:\\Coding\\portfolio-notehost\\node_modules\\notehost\\dist\\cli\\notehost\\templates'
}

Im not sure if this error was caused by me when I removed the regex match, but while I was trying the previous versions such as 1.0.9 and 1.0.8 I've encountered this same error. Adjusting the returning path manually fixed it and I was able to init

velsa commented 6 months ago

I can see the problem. This is an issue with Windows paths, which are not handled correctly by my code.

I've released a new version of notehost: 1.0.17, which should address this. Please run the init command again and lmk if you still experience crashes.

Thanks!