获取“错误:'D:\test\node_modules\uuid' 的包导出未定义'.' 子路径”一直在我需要它的时候。
操作系统 - Windows 10 Pro
节点版 - v13.1.0
NPM 版 - 6.14.4
我从头开始创建了一个项目并运行npm init -y以创建初始package.json
然后我通过运行安装了uuidnpm install uuid并创建了index.js,但只有
const { v4: uuidv4 } = require('uuid');
uuidv4();
Run Code Online (Sandbox Code Playgroud)
从他们的例子
但是每当我尝试运行此代码时,node ./index.js我总是会收到此错误:
internal/modules/cjs/loader.js:488
throw e;
^
Error: Package exports for 'D:\test\node_modules\uuid' do not define a '.' subpath
at applyExports (internal/modules/cjs/loader.js:485:15)
at resolveExports (internal/modules/cjs/loader.js:508:12)
at Function.Module._findPath (internal/modules/cjs/loader.js:577:20)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:879:27)
at Function.Module._load (internal/modules/cjs/loader.js:785:27)
at Module.require (internal/modules/cjs/loader.js:956:19) …Run Code Online (Sandbox Code Playgroud) 最近迁移mocha到jest,我遇到了一个问题.我的测试中有很多警告:
[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()
现在,将以下行添加到每个文件可以解决问题,但仅针对该特定测试文件:
jest.mock('node-uuid', () => ({ v4: jest.fn(() => 1) }));
我希望有一种方法可以node-uuid全局模拟所有测试而不是单个文件?我已经完成了一堆搜索,并在我的设置文件中尝试了不同的技术,但无济于事.
我有一个12.16.3使用 Express的非常简单的 Node.js( ) 应用程序4.17.1。我正在尝试使用 Jest26.0.1来运行测试套件,但由于整个项目中使用的uuid模块(版本8.1.0)存在一些问题,同样失败了:
[x80486@uplink:~/Workshop/node-guacamole]$ npm run test
> node-guacamole@0.3.0 test /home/x80486/Workshop/node-guacamole
> node --experimental-modules --experimental-vm-modules ./node_modules/.bin/jest --coverage --detectOpenHandles --forceExit --verbose
(node:71155) ExperimentalWarning: The ESM module loader is experimental.
FAIL src/domain/customer.test.js
? Test suite failed to run
SyntaxError: The requested module 'uuid' does not provide an export named 'v4'
at jasmine2 (node_modules/jest-jasmine2/build/index.js:228:5)
FAIL src/service/customer.service.test.js
? Test suite failed to run
SyntaxError: The requested module 'uuid' does not provide …Run Code Online (Sandbox Code Playgroud) 我目前正在使用uuidnpm 包为应用程序中的图形数据库元素生成唯一 ID node.js。
它生成符合 RFC 标准的 128 位长 ID,例如
6e228580-1cb5-11e8-8271-891867c15336
Run Code Online (Sandbox Code Playgroud)
我目前正在考虑转向shortidnpm package,它执行类似的工作,但生成 7 位长 ID:
PPBqWA9
Run Code Online (Sandbox Code Playgroud)
我的数据库请求已经很长,我想缩短它们,所以我正在考虑从 切换uuid到shortid.
然而,问题是:我知道 128 位长的 UUID 生成器保证它是唯一的。那7位的呢?我知道它可以提供78364164096独特的可能性,这还不错,但是我的数据库中已经有大约 50M 的独特对象,每个对象都有一个唯一的索引,所以我只是好奇该算法是否真的能够生成唯一的索引ID考虑到78364164096仅是50000的1350倍。
有任何想法吗?我应该使用 7 位标识符还是 128 位标识符?
这个标题有一些问题,但我有。尝试了其中的所有解决方案,但我无法解决这个问题。
我刚刚开始学习 React-Native 并收到此错误:
我已经尝试过这个红色框中提到的步骤。我尝试删除node_modules文件夹然后重新安装。我也换了"uuidv4": "^5.0.1"版本,npm install重新安装了。但没有成功。我使用过的代码uuidv4是:
const [items, setItems] = useState([
{ id: uuid(), text: 'Milk' },
{ id: uuid(), text: 'Eggs' },
{ id: uuid(), text: 'Bread' },
{ id: uuid(), text: 'Juice' }
]);
Run Code Online (Sandbox Code Playgroud)
我已将其导入为import { uuid } from 'uuidv4';
有什么帮助吗?
使用诸如uuid如何生成以下结构的模块。
[
'd9baea4e-2436-4481-accb-7c2fe835039e',
'60152666-8c2c-4d33-a5c8-da1dda106c5d',
'c4eaa558-83cc-4b94-9aff-1aefdc204794',
'273998e3-3138-41eb-b740-28ee53f7e344'
]
Run Code Online (Sandbox Code Playgroud)
我是否正确地假设这可以通过Promise一种方法来完成,或者至少可以给出这样的方法。
node-uuid ×6
node.js ×4
node-modules ×3
uuid ×3
jestjs ×2
javascript ×1
npm ×1
promise ×1
react-native ×1
reactjs ×1