whenever I try to compile any solidity project using solidity, specifically command like truffle compile it gives me an error P.S. I tried other solutions like renaming truffle.cmd or calling truffle.cmd instead of truffle and nothing works, I used windows cmd or Git Bash same error.
> Omar@LAPTOP-F8C4IRVO MINGW64 /e/College/Semester 7/Grad Project/eth-smart-contracts-master/eth-smart-contracts-master/01-HelloWorld/finish
$ truffle compile
Compiling your contracts...
===========================
C:\Users\omaro\AppData\Roaming\npm\node_modules\truffle\node_modules\solc\soljson.js:1
(function (exports, require, module, __filename, __dirname) { var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){process["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path");Module["read"]=function read(filename,binary){filename=nodePath["normalize"](filename);var ret=nodeFS["
SyntaxError: Invalid regular expression: /C:\Users\omaro\AppData\Roaming\npm\node_modules\/: \ at end of pattern
at new RegExp (<anonymous>)
at Object.<anonymous> (C:\Users\omaro\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-core\cli.js:93:1)
at cb (util.js:353:39)
at callbackifyOnRejected (util.js:337:10)
at process._tickCallback (internal/process/next_tick.js:63:19)
I'm still learning solidity and truffle, so that the code is very simple, i don't have much space to make mistakes. my reference is https://medium.com/etherereum-salon/hello-ethereum-solan-contract-4643118a6119
I had the same error with my contract. Check your solc compiler version with
truffle version
and check solidity version of your contract.
In my case, compiler was Solidity v0.5.0 (solc-js), but the contract had pragma solidity ^0.4.11;
I simply changed it to pragma solidity ^0.5.0
and reformatted code to its version requirements, contract compiled fine after. Another way to solve the problem is to edit truffle config by adding:
compilers: {
solc: {
version: "^0.4.23" // A version or constraint - Ex. "^0.5.0"
}
}