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

[Bug] shipped .mjs bundle includes reference to __dirname #79

Closed
josh-hemphill opened this issue Nov 23, 2021 · 9 comments · Fixed by #80
Closed

[Bug] shipped .mjs bundle includes reference to __dirname #79

josh-hemphill opened this issue Nov 23, 2021 · 9 comments · Fixed by #80

Comments

@josh-hemphill
Copy link

josh-hemphill commented Nov 23, 2021

__dirname is not available in ES modules.
Had to switch my project to ESM for another dependency and this came up as an error.
I'm not clear on how files are handled, but maybe it's not respecting the

"exports": {
    ".": {
      "import": "./index.mjs",
      "require": "./index.cjs"
    },
    "./*": "./*"
  },

from the package.json of auto-imported modules

@josh-hemphill josh-hemphill changed the title .mjs bundle includes reference to __dirname shipped .mjs bundle includes reference to __dirname Nov 23, 2021
@josh-hemphill josh-hemphill changed the title shipped .mjs bundle includes reference to __dirname [Bug] shipped .mjs bundle includes reference to __dirname Nov 23, 2021
@antfu
Copy link
Member

antfu commented Nov 23, 2021

We could use this https://antfu.me/notes#isomorphic-dirname, PR welcome!

@userquin
Copy link
Member

@josh-hemphill can you test with new version 0.4.16? (0.4.15 failing while publishing).

@josh-hemphill
Copy link
Author

josh-hemphill commented Nov 23, 2021

Still getting it.

ReferenceError: __dirname is not defined
    at vueuse_core_default (file:///C:/Users/joshua/test/node_modules/unplugin-auto-import/dist/chunk-7XNAUYVJ.mjs:289:87)
    at file:///C:/Users/joshua/test/node_modules/unplugin-auto-import/dist/chunk-C7LMGRZJ.mjs:42:51
    at Array.forEach (<anonymous>)
    at flattenImportsMap (file:///C:/Users/joshua/test/node_modules/unplugin-auto-import/dist/chunk-C7LMGRZJ.mjs:37:16)
    at resolveOptions (file:///C:/Users/joshua/test/node_modules/unplugin-auto-import/dist/chunk-C7LMGRZJ.mjs:18:19)
    at file:///C:/Users/joshua/test/node_modules/unplugin-auto-import/dist/chunk-C7LMGRZJ.mjs:181:20
    at file:///C:/Users/joshua/test/node_modules/unplugin/dist/index.mjs:53:23
    at file:///C:/Users/joshua/test/vite.config.ts.js?t=1637687311754:72:5
    at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
    at async Loader.import (node:internal/modules/esm/loader:178:24)
/* unplugin-auto-import/dist/chunk-7XNAUYVJ.mjs:289:87 */
// src/presets/vueuse-core.ts
import resolve from "resolve";
var _cache;
var vueuse_core_default = () => {
  const excluded = ["toRefs", "utils"];
  if (!_cache) {
    try {
      const path = resolve.sync("@vueuse/core/indexes.json", { paths: [process.cwd(), __dirname] });

@userquin
Copy link
Member

have you update the dep? If so, remove the pnpm/.vite directory. The module you reference is missing:

imagen

@josh-hemphill
Copy link
Author

I had to uninstall and reinstall. Now it works. Thanks!

@josh-hemphill
Copy link
Author

Now I'm getting another, I can open another issue if you like, but I thought I'd post here first since it's along the same vein.

failed to load config from C:\Users\joshua\test\vite.config.ts
Error: Dynamic require of "os" is not supported
    at __require (file:///C:/Users/joshua/test/node_modules/vite-plugin-inspect/dist/index.mjs:26:9)
    at node_modules/.pnpm/[email protected]/node_modules/supports-color/index.js (file:///C:/Users/joshua/test/node_modules/vite-plugin-inspect/dist/index.mjs:1156:14)
    at __require2 (file:///C:/Users/joshua/test/node_modules/vite-plugin-inspect/dist/index.mjs:29:44)
    at node_modules/.pnpm/[email protected]/node_modules/chalk/source/index.js (file:///C:/Users/joshua/test/node_modules/vite-plugin-inspect/dist/index.mjs:1412:56)
    at __require2 (file:///C:/Users/joshua/test/node_modules/vite-plugin-inspect/dist/index.mjs:29:44)
    at file:///C:/Users/joshua/test/node_modules/vite-plugin-inspect/dist/index.mjs:34444:31
    at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
    at async Loader.import (node:internal/modules/esm/loader:178:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
    at async loadConfigFromFile (C:\Users\joshua\test\node_modules\vite\dist\node\chunks\dep-e0fe87f8.js:68598:31)

@userquin
Copy link
Member

@josh-hemphill it seems the problem is on vite-plugin-inspect, please raise on that repo a new issue, can you comment out the inpsect plugin and confirm that this plugin is working with the fix on the new release?

@josh-hemphill
Copy link
Author

Oh, yep. Sorry about that.

@userquin
Copy link
Member

Oh, yep. Sorry about that.

Issue created on vite-plugin-inspect

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

Successfully merging a pull request may close this issue.

3 participants