truffle-box/react-box

Module not found: Can't resolve './build/contracts/SimpleStorage.json'

eunnovax opened this issue · 1 comments

Whenever I execute step 5:
cd client
npm run start

I get the above error. It kind of make sense because /build folder is not inside /src folder, but since
import SimpleStorageContract from "./build/contracts/SimpleStorage.json";
command has been in App.js by default, it doesn't make any sense to me.

Solved the issue by:

  1. first installing symlink package:
    npm i symlink-dir

  2. then writing LinkContracts.js script in /client:

"use strict";
const symlinkDir = require("symlink-dir");
const path = require("path");

symlinkDir("../build/contracts", "src/contracts")
.then(result => {
console.log(result);
//> { reused: false }

return symlinkDir("../build/contracts", "src/contracts");

})
.then(result => {
console.log(result);
//> { reused: true }
})
.catch(err => console.error(err));

  1. and at last creating symlink command in package.json scripts:
    "scripts": {
    "link-contracts": "node LinkContracts.js"
    }