🧮

@types/crypto-js を使ったときにGenerateできない問題の修正

2021/03/27に公開

yarn add @types/crypto-js すると、yarn generate がコケる。

$ yarn generate
...
ERROR in <path-to-project>/node_modules/secure-ls/dist/secure-ls.d.ts
ERROR in <path-to-project>/node_modules/secure-ls/dist/secure-ls.d.ts(4,9):
4:9 Module '"<path-to-project>/node_modules/@types/crypto-js"' has no exported member 'CipherHelper'.
    2 | 
    3 | import * as LZString from 'lz-string';
  > 4 | import {CipherHelper, Encoder} from 'crypto-js';
      |         ^
    5 | 
    6 | declare class SecureLS {
    7 |     constructor(config?: { isCompression?: boolean, encodingType?: string, encryptionSecret?: string , encryptionNamespace?: string });

ERROR in <path-to-project>/node_modules/secure-ls/dist/secure-ls.d.ts
ERROR in <path-to-project>/node_modules/secure-ls/dist/secure-ls.d.ts(4,23):
4:23 Module '"<path-to-project>/node_modules/@types/crypto-js"' has no exported member 'Encoder'.
    2 | 
    3 | import * as LZString from 'lz-string';
  > 4 | import {CipherHelper, Encoder} from 'crypto-js';
      |                       ^
    5 | 
    6 | declare class SecureLS {
    7 |     constructor(config?: { isCompression?: boolean, encodingType?: string, encryptionSecret?: string , encryptionNamespace?: string });

 FATAL  Nuxt build error                                                                                                                                         19:29:50

  at WebpackBundler.webpackCompile (node_modules/@nuxt/webpack/dist/webpack.js:5497:21)
  at processTicksAndRejections (internal/process/task_queues.js:93:5)
  at async WebpackBundler.build (node_modules/@nuxt/webpack/dist/webpack.js:5446:5)
  at async Builder.build (node_modules/@nuxt/builder/dist/builder.js:5634:5)
  at async Generator.initiate (node_modules/@nuxt/generator/dist/generator.js:171:7)
  at async Generator.generate (node_modules/@nuxt/generator/dist/generator.js:133:5)
  at async Object.run (node_modules/@nuxt/cli/dist/cli-generate.js:376:24)
  at async NuxtCommand.run (node_modules/@nuxt/cli/dist/cli-index.js:2803:7)


   ╭─────────────────────────────╮
   │                             │
   │   ✖ Nuxt Fatal Error        │
   │                             │
   │   Error: Nuxt build error   │
   │                             │
   ╰─────────────────────────────╯

error Command failed with exit code 1.

修正方法

@types/crypto-js のバージョンを ^3.1.47 にする。

{
  ...
  "dependencies": {
    ...
    "@types/crypto-js": "^4.0.1", <- ココ
  }
}

参照

https://github.com/softvar/secure-ls/issues/50

Discussion