unjs / mlly

🤝 Common ECMAScript module utils
MIT License
471 stars 36 forks source link

resolvePath's result is different from the module's path. #206

Closed wiidede closed 1 year ago

wiidede commented 1 year ago

Environment

@types/node 20.9.1 mlly 1.4.2

Reproduction

https://stackblitz.com/~/github.com/wiidede/mlly-arco

Describe the bug

resolvePath's result is different from the module's path.

some package.json does not provide exports field.

And the return value of resolvePath is main field. I think it should be the module field.

import '@arco-design/web-vue'

module "/home/wiidede/mlly-arco/node_modules/.pnpm/@arco-design+web-vue@2.53.2_vue@3.3.8/node_modules/@arco-design/web-vue/es/index"

console.log(resolvePathSync('@arco-design/web-vue'))

/home/wiidede/mlly-arco/node_modules/.pnpm/@arco-design+web-vue@2.53.2_vue@3.3.8/node_modules/@arco-design/web-vue/lib/index.js

packageConfig

{
  pjsonPath: "/Users/wangziyu/github/nuxt/playground/node_modules/@arco-design/web-vue/package.json",
  exists: true,
  main: "lib/index.js",
  name: "@arco-design/web-vue",
  type: "none",
  exports: undefined,
  imports: undefined,
}

Additional context

No response

Logs

No response

pi0 commented 1 year ago

Hi.

resolve method imported from path/node:path actually does not resolves a module path from node_modules. It just concatinates current working directory to it's beginning.

module field was an unstandard top level field used by bundlers (such as rollup, webpack, esbuild) to pick the bundler friendly ESM build. Native ESM only allows main and exports.

I have checked @arco-design/web-vue package.json, please consider adding an export field to package.json to properly work.

wiidede commented 1 year ago

I understand. Thank you for your detailed explanation.