vue2使用最新版nanoid,运行报错

发布时间 2023-04-18 17:13:11作者: 啦啦啦小辫子

项目需要nanoid生成主键。

vue版本:2.6.14

npm i nanoid后,npm run serve报错:

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\projects\frontend\vue-test\node_modules\_nanoid@4.0.2@nanoid\non-secure\index.js from C:\projects\frontend\vue-test\node_modules\postcss\lib\input.js not supported.
Instead change the require of index.js in C:\projects\frontend\vue-test\node_modules\postcss\lib\input.js to a dynamic import() which is available in all CommonJS modules.

网上的解决办法,package.json添加"type": "module",并没用

遂切换nanojs版本,到3.3.6,就没问题了。