extending create-react-app getting Relative imports outside of src/ are not supported

Viewed 343

I'm trying to extend the create-react-app with new folders and files outside of the /src directory. But this is by default not allowed by create-react-app. I tried to import a .json with this command: const contractABI = require('../../artifacts/contracts/MyNFT.sol/MyNFT.json') The error message:

Module not found: You attempted to import ../../artifacts/contracts/MyNFT.sol/MyNFT.json which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.

I tried to create a symbolic link like so: mklink /d \MyContracts \artifacts\contracts\MyNFT.sol This was successful \MyContracts <<===>> \artifacts\contracts\MyNFT.sol

Now, how can I import it into my react javascript file? I tried const contractABI = require('MyContracts/MyNFT.json') without success.

Any help would be great or any other approach how to solve this issue. Thanks a lot

1 Answers

I found a workaround by adding paths: {artifacts: "./src/artifacts"} to the hardhat.config.js I could configure that hardhat should create the directories and files inside the /src.

Related