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

Illegal operation on a directory, open #7148

Closed
dmiric opened this issue Apr 25, 2024 · 5 comments
Closed

Illegal operation on a directory, open #7148

dmiric opened this issue Apr 25, 2024 · 5 comments

Comments

@dmiric
Copy link

dmiric commented Apr 25, 2024

I'm trying to install Medusa v2 on Windows 10.

I get this error when i run npm run build:

npm run build

> medusa-starter-default@0.0.1 build
> cross-env npm run clean && npm run build:server && npm run build:admin


> medusa-starter-default@0.0.1 clean
> cross-env ./node_modules/.bin/rimraf dist


> medusa-starter-default@0.0.1 build:server
> node ./build.mjs

node:internal/fs/promises:633
  return new FileHandle(await PromisePrototypeThen(
                        ^

Error: EISDIR: illegal operation on a directory, open 'D:\medusa\medusa2\dist\migrations\1690996567455-CorrectOnboardingFields.js'
    at async open (node:internal/fs/promises:633:25)
    at async Object.writeFile (node:internal/fs/promises:1212:14)
    at async writeToOut (file:///D:/medusa/medusa2/build.mjs:61:3)
    at async medusaTransform (file:///D:/medusa/medusa2/build.mjs:94:5)
    at async Promise.all (index 25)
    at async file:///D:/medusa/medusa2/build.mjs:106:1 {
  errno: -4068,
  code: 'EISDIR',
  syscall: 'open',
  path: 'D:\\medusa\\medusa2\\dist\\migrations\\1690996567455-CorrectOnboardingFields.js'
}

Node.js v21.6.1
@ByronKweh
Copy link

Can you try sudo when running npm run build?

@dmiric
Copy link
Author

dmiric commented Apr 25, 2024

According to this stack that error happens when npm tries to use a file as a directory.

https://stackoverflow.com/questions/34959038/npm-stuck-giving-the-same-error-eisdir-illegal-operation-on-a-directory-read-a

Also this breaks last step of installation with npx create app

@dmiric
Copy link
Author

dmiric commented Apr 26, 2024

I did a bit more research and I found that this code is creating directories with file names. So once it attempts to write a file of same name it gets directory instead of file.

https://github.com/medusajs/medusa-starter-default/blob/feat/v2/build.mjs#L60

@dmiric
Copy link
Author

dmiric commented Apr 26, 2024

This is how I fixed it to work on windows I didn't test it on Linux but it should work:

  let dirNameRegex = new RegExp("\\" + path.sep + "([^\\" + path.sep + "]+)$");
  await fs.mkdir(outputPath.replace(dirNameRegex, ""), { recursive: true });
  await fs.writeFile(outputPath, content);

Pull request:
Feat/v2 Fix npm build command to work on all OSes.

@shahednasser
Copy link
Member

Closing this issue as it's fixed by @dmiric 's PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants