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

fix(package.json): fix to resolve nodejs 16 deprecation message DEP0148 #10348

Closed
wants to merge 1 commit into from

Conversation

cklwblove
Copy link
Contributor

本地环境

  1. 操作系统:Mac
  2. node 版本:16.13.2
  3. vue-cli5 + + vue3 + vant 3 + ts

出现的问题

(node:20011) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./es/" in the "exports" field module resolution of the package at /Users/liwb/Desktop/liwb_work/lab/vue-offical-demo/vue-project-cli-v3-ts/node_modules/vant/package.json.
Update this package.json to use a subpath pattern like "./es/*".

修复方案

修改 packages/vant/package.json

...
"exports": {
    ".": {
      "node": {
        "import": "./lib/ssr.mjs",
        "require": "./lib/ssr.js"
      },
      "import": "./es/index.js",
      "require": "./lib/vant.cjs.js",
      "types": "./lib/index.d.ts"
    },
    "./es": "./es/index.js",
    "./lib": "./lib/vant.cjs.js",
-   "./es/": "./es/",
-   "./lib/": "./lib/",
+   "./es/": "./es/*.js",
+   "./es/*.js": "./es/*.js",
+   "./lib/": "./lib/*.js",
+   "./lib/*.js": "./lib/*.js",
    "./package.json": "./package.json"
  },
...

@chenjiahan
Copy link
Member

chenjiahan commented Mar 4, 2022

这个 PR 是否有测试过各种场景喔?不确定 ./es/*.js 能否正确匹配到多级子目录的各种文件。

es 目录下除了 js,还有 css 文件,是否会受影响?

@chenjiahan
Copy link
Member

试了下没复现这个问题,能提供复现仓库看看不

image

@cklwblove
Copy link
Contributor Author

cklwblove commented Mar 6, 2022

试了下没复现这个问题,能提供复现仓库看看不

image

没有在每个 Node.js 版本都验证,只是在 16.13.2 进行了验证,修复方案主要是参考了 element-plus。复现的仓库地址:vue-project-cli-v3-ts,执行 npm run serve 就可以看到

@cklwblove
Copy link
Contributor Author

image

@chenjiahan
Copy link
Member

我测试了一下,这个写法会导致 require('vant/lib/button') 不可用。

复现步骤:

  1. 创建 a.js
const Button = require('vant/lib/button');

console.log(Button);
  1. 执行 node ./a.js,出现以下报错

image

@chenjiahan
Copy link
Member

Fixed in v3.5.0

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

Successfully merging this pull request may close these issues.

2 participants