LoginSignup
1
3

More than 3 years have passed since last update.

ユニークなIDを生成するuuidの3系 -> 7.0.3に対応(Deep requiring like `const uuidv4 = require('uuid/v4');` is deprecated)

Posted at

ユニークなIDを付与したい

例えば、あるオブジェクトに対して、ファイル名などの被りによって処理に競合が発生してしまうとしましょう。

そんな時に使うパッケージがuuid。

使い方は皆さん下記参照。

uuid | npm

uuid 3系 -> 7.0.3にアップデート

importの仕方が変わります。
これをしないとdeprecationのWarningが出続けます。

console.js:39 Deep requiring like `const uuidv4 = require('uuid/v4');` 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は以下のように変更します。

- import uuidv4 from 'uuid/v4';
+ import { v4 as uuidv4 } from 'uuid';

これで、Warningは消えます。

以上、久々に仕事で記事を書くネタがあったので戦闘力(Contributions)を上げるために投稿してみました。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3