CNode

什么是 nodejs 的Deep Requires

问答
Lluojiyin1987发布于6 年前最后回复6 年前2 回复6194 浏览0 收藏

在 nestjs 中 引入 uuid import * as uuid from 'uuid/v1'; 提示 (node:13212) DeprecationWarning: Deep requiring like const uuidv1 = require('uuid/v1'); is deprecated as of uuid@7.x. Please require the top-level module when using the Node.js CommonJS module or use ECMAScript Modules when bundling for the browser. See https://github.com/uuidjs/uuid#deep-requires-now-deprecated for more information. 解决办法 import { v1 as uuidv } from 'uuid';

有个疑问 什么是 nodejs 的Deep Requires ?

查看回复

回复 (2)

A
atian25#1·6 年前

写的很清楚了,你之前的写法相当于 require uuid 模块下的 v1.js,这是不推荐的,应该直接 require 主模块 export 的属性

L
luojiyin1987#2·6 年前
引用 atian25写的很清楚了,你之前的写法相当于 require uuid 模块下的 v1.js,这是不推荐的,应该直接 require 主模块 export 的属性

@atian25 明白了, 我之前是完全 require uuid 下的 v1.js, 我实际上只用到 uuid 这个函数,没必要完全 require v1.js, 浪费内存。

多谢

参与回复
登录后即可参与回复。登录