Nicolay

vue + ts 中 import crypto from 'crypto' 失败,提示 Cannot find module 'crypto' or its corresponding type declarations.

  •  
  •   Nicolay · Nov 3, 2020 · 3552 views
    This topic created in 2038 days ago, the information mentioned may be changed or developed.
    请问大家该怎么办呢,我在 es6 的项目中这样写是没有问题的,
    6 replies    2020-11-06 23:01:52 +08:00
    Nicolay
        1
    Nicolay  
    OP
       Nov 3, 2020
    package.json 中是这样写的 ,crypto-js 和 crypto 都需要用,虽然我不太懂二者的区别,不过 import cryptoJs from 'crypto-js' 没有问题,
    "dependencies": {
    "@types/crypto-js": "^3.1.47",
    "@types/echarts": "^4.8.1",
    "axios": "^0.19.0",
    "crypto": "^1.0.1",
    "crypto-js": "^4.0.0",
    },
    Timefly
        2
    Timefly  
       Nov 3, 2020
    缺少类型声明文件吧,或许还要装一个 @types/crypto,先去 npm 上看看有没有
    Nicolay
        3
    Nicolay  
    OP
       Nov 3, 2020
    @Timefly 这个的确没有,
    mxT52CRuqR6o5
        4
    mxT52CRuqR6o5  
       Nov 3, 2020
    用啥打包的,crypto 是 node 自带模块,打包器不帮你打包浏览器环境是运行不了的
    Nicolay
        5
    Nicolay  
    OP
       Nov 5, 2020
    @mxT52CRuqR6o5 webpack
    mxT52CRuqR6o5
        6
    mxT52CRuqR6o5  
       Nov 6, 2020 via Android
    @Nicolay 直接换 crypto-js 吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2618 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 15:56 · PVG 23:56 · LAX 08:56 · JFK 11:56
    ♥ Do have faith in what you're doing.