nuxt / telemetry

Nuxt Telemetry
MIT License
207 stars 23 forks source link

chore(deps): update std-env #66

Closed rchl closed 2 years ago

rchl commented 2 years ago

Tried to migrate Nuxt 2 project to Bridge and got an error because std-env@2 gets hoisted and fails with:

ERROR  [worker reload] [worker init] Named export 'provider' not found. The requested module 'file:///usr/local/workspace/web/project/node_modules/std-env/index.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'file:///usr/local/workspace/web/project/node_modules/std-env/index.js';
const { provider, isWindows } = pkg;

  import { provider, isWindows } from 'node_modules/std-env/index.js';
  ^^^^^^^^
  SyntaxError: Named export 'provider' not found. The requested module 'node_modules/std-env/index.js' is a CommonJS module, which may not support all module.exports as named exports.
  CommonJS modules can always be imported via the default export, for example using:

  import pkg from 'node_modules/std-env/index.js';
  const { provider, isWindows } = pkg;

  at ModuleJob._instantiate (internal/modules/esm/module_job.js:124:21)
  at async ModuleJob.run (internal/modules/esm/module_job.js:179:5)
  at async Loader.import (internal/modules/esm/loader.js:178:24)
  at async Object.loadESM (internal/process/esm_loader.js:68:5)
rchl commented 2 years ago

BTW. The error message is quite unhelpful as:

pi0 commented 2 years ago

Thanks! BTW this error is caused because of package-managers bad hoisting and generated by Node.js. Nothing much we can do.

rchl commented 2 years ago

You went with merging https://github.com/nuxt/telemetry/pull/65, without including code changes from here which, while works on the CI, will still result in errors visible in the IDE as TS is not able to synthesise those exports.

Sorry, I don't know why I thought that this was closed and the other one merged. I must be tired. :)

BTW this error is caused because of package-managers bad hoisting and generated by Node.js. Nothing much we can do.

You can ensure that at least all internal Nuxt packages don't use widely different versions though. That helps quite a bit alone.

rchl commented 2 years ago

Oh, I misunderstood you. You meant that you can't do much about the contents of the error. Fair point then, I didn't think it's a native Node.js error.

pi0 commented 2 years ago

You can ensure that at least all internal Nuxt packages don't use widely different versions though. That helps quite a bit alone.

It isn't as easy as you might think. Nuxt 2 dependencies are legacy and Nuxt 3 are already upgraded to latest. Bridge is not enabled yet for Nuxt 3 for very same reason that it was old. Nuxt Birdge is a mix between and as a result, always things like this can happen for it. I need to release a major version of telemetry and update it for 2.16 alongside with same PR that bumps std-env for nuxt 2.