最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

无法从crypto

网站源码admin15浏览0评论

无法从crypto

无法从crypto

我正在开发Udacity的区块链纳米级程序,并且在导入SHA256时遇到了一些我不理解的错误。我确实按照github存储库(npm install)中的建议运行了。

这是我的代码:

/**
 * Step 1: Verify 'crypto-js' module is installed for your project
 * After verifying it is installed, move on to Step 2. No code needs to be written here.
 */

/**
 * Step 2: Import from crypto-js module the sha265 library
 */

// Write your code here
// import sha256 from 'crypto-js/sha256';
import SHA256 from 'crypto-js/sha256'

/**
 * Variables: Do not change variable values to be able to answer the quiz
 */

const data1 = "Blockchain Rock!";
const dataObject = {
    id: 1,
    body: "With Object Works too",
    time: new Date().getTime().toString().slice(0,-3)
};

/**
 * Step 3: Add code to the `generate hash function
 * Function that generate the SHA256 Hash
 * @param {*} obj 
 */

function generateHash(obj) {
    // Write your code here
    console.log(SHA256(JSON.stringify(obj)))
}

console.log(`SHA256 Hash: ${generateHash(data1)}`);
console.log("************************************");
console.log(`SHA256 Hash: ${generateHash(dataObject)}`);

/**
 * Run your application using `node app.js`
 */

这是我的package.json:

{
  "name": "hashing",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel": "^6.23.0",
    "crypto-js": "^3.3.0",
    "webpack": "^4.5.0"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-preset-es2015": "^6.24.1"
  }
}

[当我尝试运行node app.js时,出现此错误:

/git/nd1309_hashing/app.js:12
import SHA256 from 'crypto-js/sha256'
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1072:16)
    at Module._compile (internal/modules/cjs/loader.js:1122:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47

谁能看到我在做什么错吗?

回答如下:

替换:import SHA256 from 'crypto-js/sha256'

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论