nanoapi-io / napi

Transpile your monolithic codebases to microservices in seconds
https://nanoapi.io
Other
171 stars 3 forks source link

[BUG] ENOENT Error on Windows - Missing C:\tmp\napi_session_id Directory #38

Closed emmanuel39hanks closed 1 day ago

emmanuel39hanks commented 2 days ago

Description

When running the napi command on Windows, an error occurs due to a missing C:\tmp directory, where napi tries to create a session file (napi_session_id). This issue prevents napi from functioning correctly until the directory is created manually.

Error Message

C:\Users\emmanuel>napi init
node:fs:2352
    return binding.writeFileUtf8(
                   ^

Error: ENOENT: no such file or directory, open 'C:\tmp\napi_session_id'
    at writeFileSync (node:fs:2352:20)
    at getSessionId (C:\Users\emmanuel\AppData\Roaming\npm\node_modules\@nanoapi.io\napi\dist\telemetry.js:41:28)      
    at Object.<anonymous> (C:\Users\emmanuel\AppData\Roaming\npm\node_modules\@nanoapi.io\napi\dist\telemetry.js:44:20)    
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (C:\Users\emmanuel\AppData\Roaming\npm\node_modules\@nanoapi.io\napi\dist\index.js:18:21) {  
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'C:\\tmp\\napi_session_id'
}

Expected Behavior

The napi command should automatically create required directories or use a suitable cross-platform temporary directory such as the Windows %TEMP% environment variable, and initialize a NanoAPI project.

Actual Behavior

We get the error message ENOENT Error on Windows - Missing C:\tmp\napi_session_id Directory

Workaround

Manually create the C:\tmp directory: mkdir C:\tmp

Once the directory is created, napi init runs as expected.

Possible Fix

Update napi init command to automatically create the C:\tmp directory if it doesn’t exist. Alternatively, use the default OS temp directory (e.g., %TEMP% on Windows), which will avoid creating new directories on the root drive.

Steps to Reproduce

Install @nanoapi.io/napi globally on Windows: npm install -g @nanoapi.io/napi

Run the napi init command

Context

This issue impacts Windows users who do not have a pre-existing C:\tmp directory, which is not created by default on the OS. Adjusting this path would make the library more cross-platform compatible.

Environment

OS: Windows 11 Node.js Version: 20.11.0 npm Version: 10.7.0

florianbgt commented 2 days ago

Windows was overlooked. All the team is working on linux and did not windows into account. I think the possible fix you mention is the way to go. We should check for on platform the cli is running and create the file in the temp folder following the OS spec (temp for lniux, and whatever it is for windows). Note: It is already working on mac and linux, just need to fix for windows

emmanuel39hanks commented 2 days ago

Great, will work on the fix and I will create a PR once done.

erbesharat commented 2 days ago

@emmanuel39hanks

A recommendation for possible fix:

NodeJS has built-in functions to let you know what a user's tmp dir is depending on their operating system. Feel free to give this doc a look and looking forward to a PR!

https://nodejs.org/api/os.html#ostmpdir