Skip to content

Fix spawn npm ENOENT #96

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

Merged
merged 9 commits into from
Mar 16, 2023
Merged

Fix spawn npm ENOENT #96

merged 9 commits into from
Mar 16, 2023

Conversation

Yoinky3000
Copy link
Contributor

@Yoinky3000 Yoinky3000 commented Mar 14, 2023

This pr was created to solve:
1. The problem that esbuild can't recognize windows back-slash \ during the build and cause error

Solved by #86 already

  1. The problem that windows cant use spawn() with npx as it will cause the error
    spawn npm ENOENT

Solved by detecting the platform, spawn with npx.cmd if win32 was detected, otherwise spawn with npx
The place that was changed:

@changeset-bot
Copy link

changeset-bot bot commented Mar 14, 2023

🦋 Changeset detected

Latest commit: 4221e73

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/next-on-pages Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@james-elicx
Copy link
Contributor

If you don't mind me asking, I'm curious as to what error esbuild gives you for the entryPoints, inject, and functionsFile file paths that mean they need to be normalized. I wasn't getting any errors with them when I was testing locally - the only error I could manage to produce was for file paths located inside the files.

The normalizePath(filepath) on the hydrated entries (L484, L493) shouldn't be needed anymore as they are normalized earlier in the code when added to the functions map.

@Yoinky3000
Copy link
Contributor Author

If you don't mind me asking, I'm curious as to what error esbuild gives you for the entryPoints, inject, and functionsFile file paths that mean they need to be normalized. I wasn't getting any errors with them when I was testing locally - the only error I could manage to produce was for file paths located inside the files.

The normalizePath(filepath) on the hydrated entries (L484, L493) shouldn't be needed anymore as they are normalized earlier in the code when added to the functions map.

The error esbuild gives me is here

X [ERROR] Could not resolve "C:UsersXXXAppDataLocalTempy5e3zjw1i9sindex.func.js"

    ../../../../../AppData/Local/Temp/functions-wgc9o6l1c2.js:2:116:
      2 │     export const __FUNCTIONS__ = {"index": { matchers: [{"regexp":"^/$","originalSource":"/"}], entrypoint: require('C:\Users\XXX\AppData\Local\Temp\y5e3zjw1i9s\index.func.js')}};
        ╵                                                                                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "C:UsersXXXAppDataLocalTempy5e3zjw1i9sindex.func.js" as external to
  exclude it from the bundle, which will remove this error. You can also surround this "require"
  call with a try/catch block to handle this failure at run-time instead of bundle-time.

C:\Users\XXX\OneDrive\Documents\VSCode\LOLBRUHNICE\next-on-pages\node_modules\esbuild\lib\main.js:1566
  let error = new Error(`${text}${summary}`);
              ^

Error: Build failed with 1 error:
../../../../../AppData/Local/Temp/functions-wgc9o6l1c2.js:2:116: ERROR: Could not resolve "C:UsersXXXAppDataLocalTempy5e3zjw1i9sindex.func.js"
    at failureErrorWithLog (C:\Users\XXX\OneDrive\Documents\VSCode\LOLBRUHNICE\next-on-pages\node_modules\esbuild\lib\main.js:1566:15)
    at C:\Users\XXX\OneDrive\Documents\VSCode\LOLBRUHNICE\next-on-pages\node_modules\esbuild\lib\main.js:1024:28
    at C:\Users\XXX\OneDrive\Documents\VSCode\LOLBRUHNICE\next-on-pages\node_modules\esbuild\lib\main.js:969:67
    at buildResponseToResult (C:\Users\XXX\OneDrive\Documents\VSCode\LOLBRUHNICE\next-on-pages\node_modules\esbuild\lib\main.js:1022:7)
    at C:\Users\XXX\OneDrive\Documents\VSCode\LOLBRUHNICE\next-on-pages\node_modules\esbuild\lib\main.js:1134:14
    at responseCallbacks.<computed> (C:\Users\XXX\OneDrive\Documents\VSCode\LOLBRUHNICE\next-on-pages\node_modules\esbuild\lib\main.js:671:9)
    at handleIncomingPacket (C:\Users\XXX\OneDrive\Documents\VSCode\LOLBRUHNICE\next-on-pages\node_modules\esbuild\lib\main.js:726:9)
    at Socket.readFromStdout (C:\Users\XXX\OneDrive\Documents\VSCode\LOLBRUHNICE\next-on-pages\node_modules\esbuild\lib\main.js:647:7)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12) {
  errors: [
    {
      detail: undefined,
      id: '',
      location: {
        column: 116,
        file: '../../../../../AppData/Local/Temp/functions-wgc9o6l1c2.js',
        length: 61,
        line: 2,
        lineText: `    export const __FUNCTIONS__ = {"index": { matchers: [{"regexp":"^/$","originalSource":"/"}], entrypoint: require('C:\\Users\\XXX\\AppData\\Local\\Temp\\y5e3zjw1i9s\\index.func.js')}};`,
        namespace: '',
        suggestion: ''
      },
      notes: [
        {
          location: null,
          text: 'You can mark the path "C:UsersXXXAppDataLocalTempy5e3zjw1i9sindex.func.js" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.'
        }
      ],
      pluginName: '',
      text: 'Could not resolve "C:UsersXXXAppDataLocalTempy5e3zjw1i9sindex.func.js"'
    }
  ],
  warnings: []
}

though I found that your changes also solved this problem as you make it normalize the path before it was put into the functionsMap after I test it

@james-elicx
Copy link
Contributor

though I found that your changes also solved this problem as you make it normalize the path before it was put into the functionsMap after I test it

I thought that would be the case. Seems like the other normalizePaths you did might not be needed then.

@Yoinky3000 Yoinky3000 changed the title Fix windows related error Fix spawn npm ENOENT Mar 16, 2023
@Yoinky3000
Copy link
Contributor Author

though I found that your changes also solved this problem as you make it normalize the path before it was put into the functionsMap after I test it

I thought that would be the case. Seems like the other normalizePaths you did might not be needed then.

yeah, I just removed the changes I made with the path

@github-actions
Copy link
Contributor

🧪 A prerelease is available for testing 🧪

You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/next-on-pages/runs/4438929823/npm-package-next-on-pages-96

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/next-on-pages/prs/96/npm-package-next-on-pages-96

@dario-piotrowicz
Copy link
Member

Thanks a lot @james-elicx for the assistance in reviewing the PR! (it's ultra appreciated especially since we're currently not really well equipped to test the package on windows)

And thanks a lot @LOLBRUHNICE of course! 🙂

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

Successfully merging this pull request may close these issues.

Error: spawn npm ENOENT
3 participants