Having trouble utilizing installed npm packages like fs-extra in the js files provided by Truffle. The error message "can't find module 'fs-extra'" keeps popping up.
1) Attempted to import local js files using the require() method, but it was unsuccessful.
2) Running separate js files using node works without any issues.
3) The problem arises when trying to use require("fs-extra")
inside a function declared within the APP object.
App = {
web3Provider: null,
contracts: {},
init: async function () {
return await App.initWeb3();
},
initWeb3: async function () {
// Modern dapp browsers...
if (window.ethereum) {
App.web3Provider = window.ethereum;
try {
// Request account access
await window.ethereum.enable();
} catch (error) {
// User denied account access...
console.error("User denied account access")
}
}
// Legacy dapp browsers...
else if (window.web3) {
App.web3Provider = window.web3.currentProvider;
}
// If no injected web3 instance is detected, fall back to Ganache
else {
App.web3Provider = new Web3.providers.HttpProvider('http://0.0.0.0:9283');
}
web3 = new Web3(App.web3Provider);
return App.initContract();
},
initContract: function () {
$.getJSON('UserCreation.json', function (data) {
var CMArtifact = data;
App.contracts.UserCreation = TruffleContract(CMArtifact);
App.contracts.UserCreation.setProvider(App.web3Provider);
});
return App.bindEvents();
},
createUser: function (event) {
event.preventDefault();
var username = $("#sign-up-username").val();
var title = $("#sign-up-title").val();
var intro = $("#sign-up-intro").val();
const utility=require('fs-extra'); // Unable to locate module
}
}
$(function () {
console.log("Initializing farmer")
$(window).load(function () {
App.init();
});
});
Expected: Should be able to call methods from the fs-extra package
Actual : Error persists - can't find module "fs-extra"