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 './globalThis.js' #204

Closed
Tracked by #9
productdevbook opened this issue Nov 5, 2021 · 5 comments · Fixed by nuxt/framework#1835
Closed
Tracked by #9

Could not resolve './globalThis.js' #204

productdevbook opened this issue Nov 5, 2021 · 5 comments · Fixed by nuxt/framework#1835
Labels
bridge bug Something isn't working nuxt3

Comments

@productdevbook
Copy link
Member

Environment


  • Operating System: Darwin
  • Node Version: v16.13.0
  • Nuxt Version: 3.0.0-27267816.6bd7186
  • Package Manager: yarn@1.22.17
  • Bundler: Vite
  • User Config: buildModules, build
  • Runtime Modules: -
  • Build Modules: nuxt-windicss@2.0.11

Describe the bug

yarn build

Reproduction

https://github.com/productdevbook/productdevbook.com

Additional context

No response

Logs

yarn run v1.22.17
$ nuxi build
Nuxt CLI v3.0.0-27267528.292b524                                                                                                                                                                                        06:46:08

 ERROR  Could not resolve './globalThis.js' from node_modules/@apollo/client/utilities/globals/index.js                                                                                                                 06:46:12


 ERROR  Could not resolve './globalThis.js' from node_modules/@apollo/client/utilities/globals/index.js                                                                                                                 06:46:12

  at error (node_modules/rollup/dist/shared/rollup.js:158:30)
  at ModuleLoader.handleResolveId (node_modules/rollup/dist/shared/rollup.js:22306:24)
  at node_modules/rollup/dist/shared/rollup.js:22300:26

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@productdevbook productdevbook added bug Something isn't working nuxt3 labels Nov 5, 2021
@danielroe danielroe assigned danielroe and unassigned danielroe Nov 5, 2021
@nachtfunke
Copy link

Did you maybe find a solution for this? I am facing the exact same issue, but with globalThis.scss.

@nachtfunke
Copy link

Should anyone stumble upon the same issue, just renaming the files in question actually will help to circumvent this specific issue.

@AeonFr
Copy link

AeonFr commented Nov 10, 2021

Getting a similar error when running npx nuxi build

Using node 14 and npm 6

❯ npx nuxi build
Nuxt CLI v3.0.0-27274229.29599f0                                                                                                                                      10:19:03
ℹ Vite warmed up in 1026ms                                                                                                                                            10:19:05

 ERROR  Could not resolve '../util/globalThis' from ../util/globalThis?commonjs-external                                                                              10:19:06


 ERROR  Could not resolve '../util/globalThis' from ../util/globalThis?commonjs-external                                                                              10:19:06

  at error (node_modules/rollup/dist/shared/rollup.js:158:30)
  at ModuleLoader.handleResolveId (node_modules/rollup/dist/shared/rollup.js:22306:24)
  at node_modules/rollup/dist/shared/rollup.js:22300:26

I don't have Elemen Plus installed, not sure what to do.

@AeonFr
Copy link

AeonFr commented Nov 10, 2021

This is probably an insane solution, but I managed to get build to work by following this steps:

  1. Add this to your nuxt config:
  vite: {
    resolve: {
      alias: {
        "../util/globalThis": "./dirty-hack.js",
      },
    },
  },

(in my case, unlike OP's, the problematic import was ../util/globalThis, so I added an alias for that. If you are having issues with ../globalThis instead, adjust the alias)

  1. Create a dirty-hack.js file in the root of the project. I'm not sure if the content is important, I left mine black except for a comment
// Trying to bypass showstopper bug that prevents builds
// See issue status: nuxt/bridge#204

After those steps building the app should be possible


UPDATE

After applying the fix above, a regular build now works, but I'm getting a different error if I use the NITRO_PRESET=cloudflare config 😭

 ERROR  Rollup error: Could not load buffer/index.js (imported by node_modules/h3/dist/index.mjs): ENOENT: no such file or directory, open 'buffer/index.js'          10:44:25


 ERROR  Could not load buffer/index.js (imported by node_modules/h3/dist/index.mjs): ENOENT: no such file or directory, open 'buffer/index.js'                        10:44:25



npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ build-cloudflare: `NITRO_PRESET=cloudflare nuxi build`

Would really appreciate any advancement on this.

@genffy
Copy link

genffy commented Nov 10, 2021

this bug cause by this line https://github.com/nuxt/framework/blob/bf716f39783508e001a590c01956ac57937f6bd2/packages/vite/src/client.ts#L21
doc in vite describe this config mean just simple replace variable when build
https://github.com/vitejs/vite/blob/f6d08c7430906d6262ee1df729d2ea193a80fa6c/packages/vite/src/node/config.ts#L110

/**
 * Define global variable replacements.
 * Entries will be defined on `window` during dev and replaced during build.
 */
define?: Record<string, any>

when file path has some variable in define, also will be repaced.

Reproduction project: https://codesandbox.io/s/charming-darkness-fdvg9?file=/app.vue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bridge bug Something isn't working nuxt3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants