gpt4 book ai didi

node.js - 错误 [ERR_PACKAGE_PATH_NOT_EXPORTED] : Package subpath './v4' is not defined by "exports"

转载 作者:行者123 更新时间:2023-12-03 12:10:15 32 4
gpt4 key购买 nike

使用 uuidv4 时出现此错误。

Failure: Package subpath './v4' is not defined by "exports" in C:\Users\mycomp\Desktop\Programming\Javascript\Serverless\Serverless Framework\node_modules\uuid\package.json
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './v4' is not defined by "exports" in C:\Users\mycomp\Desktop\Programming\Javascript\Serverless\Serverless Framework\node_modules\uuid\package.json
我已经安装了 uuid 并在我的代码中需要它
const uuidv4 = require('uuid/v4');
这是 package.json
"dependencies": {
"aws-sdk": "^2.702.0",
"moment": "^2.27.0",
"serverless-offline": "^6.4.0",
"underscore": "^1.10.2",
"uuid": "^8.1.0"
}

最佳答案

ECMAScript 模块语法:

import { v4 as uuidv4 } from 'uuid';
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
CommonJS 语法:
const { v4: uuidv4 } = require('uuid');
uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'

关于node.js - 错误 [ERR_PACKAGE_PATH_NOT_EXPORTED] : Package subpath './v4' is not defined by "exports",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62549457/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com