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

Could not resolve node_modules/@esbuild-plugins/node-globals-polyfill/_virtual-process-polyfill_.js" #1

Open
inc16sec opened this issue Dec 21, 2022 · 6 comments

Comments

@inc16sec
Copy link

Hey @dnalborczyk I was trying to use your package to deploy my Apollo server V4 into Cloudflare Workers (looks like this is the only way so far).. And as I tried to build the project by running rimraf build && NODE_ENV=production node worker.build.js it threw an error;

[ERROR] Could not resolve "/../../..../../apollo_server_worker/node_modules/@esbuild-plugins/node-globals-polyfill/_virtual-process-polyfill_.js"

I'm not sure what is the issue here.

here's my package.json

{
  "name": "apollo_server_worker",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "build": "rimraf build && NODE_ENV=production node worker.build.js",
    "start": "wrangler dev --experimental-local",
    "deploy": "wrangler publish"
  },
  "dependencies": {
    "@apollo/server": "^4.3.0",
    "@neo4j/graphql": "^3.14.1",
    "@neo4j/graphql-plugin-auth": "^1.1.1",
    "@tsndr/cloudflare-worker-jwt": "^2.1.4",
    "apollo-server-integrations-cloudflare-workers": "^0.1.5",
    "dotenv": "^16.0.3",
    "graphql": "^16.6.0",
    "neo4j-driver": "^5.3.0"
  },
  "devDependencies": {
    "@cloudflare/workers-types": "^4.20221111.1",
    "@esbuild-plugins/node-globals-polyfill": "^0.1.1",
    "@esbuild-plugins/node-modules-polyfill": "^0.1.4",
    "@miniflare/tre": "^3.0.0-next.10",
    "@typescript-eslint/eslint-plugin": "^5.46.1",
    "@typescript-eslint/parser": "^5.46.1",
    "esbuild": "^0.16.7",
    "eslint": "^8.29.0",
    "prettier": "^2.8.1",
    "rimraf": "^3.0.2",
    "typescript": "^4.9.4",
    "wrangler": "2.6.2"
  },
  "type": "module"
}

I also have added the files in this exapmle project, inclduing.

src/index.ts
prettier.config.cjs
tsconfig.json
worker.build.js
wrangler.toml

When I try to run wrangler dev --experimental-local without building it throws "The entry-point file at "dist/index.js" was not found." And when I run the build command it throws the error mentioned above.

Is there something I'm missing here? Are there some more steps that I've skipped?
Also. The project need to be built first before running it. right ?

Thank you for your work and I hope to hear from you soon.
Best regards.

@dnalborczyk
Copy link
Owner

dnalborczyk commented Dec 23, 2022

hey @inc16sec I'll have a look.

update: I'm able to reproduce. I'm guessing it's a dependency issue with a later version of esbuild.

@inc16sec
Copy link
Author

inc16sec commented Dec 23, 2022

Hey @dnalborczyk. After doing some digging, I found that the issue is from my end. You see I'm using Apollo/server and Neo4j-driver.. Neo4j-driver relies on some node scripts to run and it seems that it is what leads to the error.
At this point, I don't think I'll be able to deploy my server with workers.. Still waiting for firebase-functions integration, hopefully, I can deploy my server with it.
Thank you again for your work and your response.. It is much appreciated.

@dnalborczyk
Copy link
Owner

dnalborczyk commented Dec 23, 2022

ah, ok, no problem 👍

if you are still interested: it was not any of your fault. in order to get it to work you have to pin esbuild to "0.16.7" for now, no quite sure why or what broke the globals-polyfill-plugin. I might digg in a bit later.

@inc16sec
Copy link
Author

ah, ok, no problem 👍

if you are still interested: it was not any of your fault. in order to get it to work you have to pin esbuild to "0.16.7" for now, no quite sure why or what broke the globals-polyfill-plugin. I might digg in a bit later.

I do have esbuild set to "0.16.7" and still, when I want to build by running npm run build I still get this error.

Could not resolve "/../../../../PROJECT_DEV/apollo_server_worker/node_modules/@esbuild-plugins/node-globals-polyfill/_virtual-process-polyfill_.js"

@dnalborczyk
Copy link
Owner

just digged a bit: https://github.com/evanw/esbuild/releases/tag/v0.16.8 , fairly sure this Allow plugins to resolve injected files (https://github.com/evanw/esbuild/issues/2754) is the issue.

there has been multiple issues filed fir this in the global polyfill repo: https://github.com/remorses/esbuild-plugins/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc

the problem is that those plugin repos are pretty much unmaintained right now. 😞

you could try:

npm i [email protected]
rm -rf node_modules
npm ci

@inc16sec
Copy link
Author

just digged a bit: https://github.com/evanw/esbuild/releases/tag/v0.16.8 , fairly sure this Allow plugins to resolve injected files (https://github.com/evanw/esbuild/issues/2754) is the issue.

there has been multiple issues filed fir this in the global polyfill repo: https://github.com/remorses/esbuild-plugins/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc

the problem is that those plugin repos are pretty much unmaintained right now. 😞

you could try:

npm i [email protected]
rm -rf node_modules
npm ci

After running

npm i [email protected]
rm -rf node_modules
npm ci

I was able to run the build command successfully and it indeed built the project but when running npm run start it threw another error which is "probably" caused by neo4j-driver "again" for depending on node scripts.

Here's the error.

service core:user:apollo_server_worker: Uncaught TypeError: globalThis.XMLHttpRequest is not a constructor
  at index.js:67276:15 in Due
  at index.js:67300:116
  at index.js:80:37
  at index.js:67468:3
  at index.js:80:37
  at index.js:67918:3
  at index.js:80:37
  at index.js:67926:13
  at index.js:81:31
  at index.js:67943:13
✘ [ERROR] The Workers runtime failed to start. There is likely additional logging output above.

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

2 participants