什么是 nodejs 的Deep Requires
发布于 5 年前 作者 luojiyin1987 6035 次预览 最后一次回复是 5 年前 来自 问答
在 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 回复
写的很清楚了,你之前的写法相当于 require uuid 模块下的 v1.js,这是不推荐的,应该直接 require 主模块 export 的属性
@atian25 明白了, 我之前是完全 require uuid 下的 v1.js, 我实际上只用到 uuid 这个函数,没必要完全 require v1.js, 浪费内存。
多谢