sindresorhus / globby

User-friendly glob matching
MIT License
2.51k stars 130 forks source link

globby 12/ESM vs PnP? "ERR_MODULE_NOT_FOUND" #197

Closed pgnd closed 2 years ago

pgnd commented 2 years ago

reading

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
https://blog.sindresorhus.com/get-ready-for-esm-aa53530b3f77

editing

webpack.config.js
    ...
-   const globby = require('globby');
+   import {globby} from 'globby';
    ...

package.json
    {
+     "type": "module",
      "packageManager": "yarn@3.1.0",
    ...

with env

node --version
    v16.13.0

yarn --version
    3.1.0

cat .yarnrc.yml
    yarnPath: .yarn/releases/yarn-3.1.0.cjs

yarn info --name-only globby
    └─ globby@npm:12.0.2

now returns

[webpack-cli] Failed to load '/test/app1/webpack.config.js' config
[webpack-cli] Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'globby' imported from /test/app1/webpack.config.js
Did you mean to import globby-npm-12.0.2-6be2a4aac6-f474ced866.zip/node_modules/globby/index.js?
    at new NodeError (node:internal/errors:371:5)
    at packageResolve (node:internal/modules/esm/resolve:884:9)
    at moduleResolve (node:internal/modules/esm/resolve:929:18)
    at defaultResolve (node:internal/modules/esm/resolve:1044:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:422:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

iiuc, the issue's Yarn PnP

https://github.com/hoangvvo/next-connect/issues/163

is there a current workaround for globby? or, to use it in v12+, is it required to not use PnP?

sindresorhus commented 2 years ago

This is not a support forum for Webpack or Yarn. This package implements ESM correctly. Use the Webpack or Yarn issue tracker for support.

pgnd commented 2 years ago

lol

Eli-Black-Work commented 1 year ago

Updating to Yarn 3 (specifically, 3.3.0) fixed the issue for us, as that version of Yarn has support for ESM 🙂