Warning: Source file does not specify required compiler version! Consider adding "pragma solidity ^0.5.16;"

:computer: Environment


:1234: Code to reproduce

When i try to compile it gives me this

Warning: Source file does not specify required compiler version! Consider adding "pragma solidity ^0.5.16;"

i honestly don’t know what to do anymore. I don’t kniw if i installed anything right. and if i try to migrate it tell me

2_deplocontract.js invalid or does not take any parameters
    at Migration._load (C:\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:49:1)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Migration.run (C:\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:171:1)
    at Object.runMigrations (C:\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)
    at Object.runFrom (C:\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1)
    at Object.run (C:\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:87:1)
    at runMigrations (C:\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:262:1)
    at Object.run (C:\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:227:1)
    at Command.run (C:\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\command.js:136:1)
Truffle v5.1.66 (core: 5.1.66)
Node v14.15.4

I am totally lost and tired.

Also If i try to open @openzeppelin contracts, i see two different node_modules. i don’t know if that right.

1 Like

Hi @therunaway,

Welcome to the community :wave:

I suggest (if you haven’t already) that you look at the OpenZeppelin Learn guides:

The first error is that the contract you are writing doesn’t specify what Solidity compiler version to use, so you should add a pragma that specifies this.

the second error is that there is an issue with your migration script 2_deplocontract.js.

Getting your environment setup can be a challenge. It may be worth looking at Windows Subsystem for Linux, I use WSL2 on Windows 10. Though you are ok to stick with Windows for now.

When you say two different node_modules, I assume that you have that directory in your project root and also in another directory (such as your application source).

I ran it one time and it worked , I tried it another time and it didn’t. This is the second linux recommendation I am getting, so I have decided to change my OS to linux. I really don’t mind. I just need something that works. Thank you very much.

1 Like

HI @therunaway,

Much of the ecosystem is built and tested on Linux.

I have developed smart contracts on Windows 7 and used to find that tools wouldn’t always work.

I have been using Windows Subsystem for Linux (WSL and then WSL2) on Windows 10 for a couple of years now and recommend it. See: Solidity Smart Contract development on Windows

I am on linux now. and i have this problem

Error: Cannot find module '@truffle/db'
Require stack:
- /home/.nvm/versions/node/v15.10.0/lib/node_modules/truffle/build/cli.bundled.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:923:15)
    at Function.Module._load (node:internal/modules/cjs/loader:768:27)
    at Module.require (node:internal/modules/cjs/loader:995:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.168060 (/home/.nvm/versions/node/v15.10.0/lib/node_modules/truffle/build/webpack:/external "@truffle/db":1:1)
    at __webpack_require__ (/home/.nvm/versions/node/v15.10.0/lib/node_modules/truffle/build/webpack:/webpack/bootstrap:18:1)
    at Object.577135 (/home/.nvm/versions/node/v15.10.0/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/index.js:12:28)
    at __webpack_require__ (/home/.nvm/versions/node/v15.10.0/lib/node_modules/truffle/build/webpack:/webpack/bootstrap:18:1)
    at Object.run (/home/.nvm/versions/node/v15.10.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/compile.js:66:29)
    at Command.run (/home/.nvm/versions/node/v15.10.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:136:1)
    at Object.586806 (/home/.nvm/versions/node/v15.10.0/lib/node_modules/truffle/build/webpack:/packages/core/cli.js:51:1)
    at __webpack_require__ (/home/.nvm/versions/node/v15.10.0/lib/node_modules/truffle/build/webpack:/webpack/bootstrap:18:1)
    at __webpack_require__.x (/home/.nvm/versions/node/v15.10.0/lib/node_modules/truffle/build/webpack:/webpack/bootstrap:36:1)
    at Function.__webpack_require__.x (/home/.nvm/versions/node/v15.10.0/lib/node_modules/truffle/build/webpack:/webpack/runtime/startup chunk dependencies:32:1)
    at /home/.nvm/versions/node/v15.10.0/lib/node_modules/truffle/build/webpack:/webpack/startup:3:1
    at Object.<anonymous> (/home/.nvm/versions/node/v15.10.0/lib/node_modules/truffle/build/cli.bundled.js:629:12)
    at Module._compile (node:internal/modules/cjs/loader:1091:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1120:10)
    at Module.load (node:internal/modules/cjs/loader:971:32)
    at Function.Module._load (node:internal/modules/cjs/loader:812:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47
Truffle v5.2.0 (core: 5.2.0)
Node v15.10.0

please help me out

1 Like

Hi @therunaway,

This looks like it was an issue with Truffle: https://github.com/trufflesuite/truffle/issues/3896#issuecomment-788474543
If you uninstall Truffle and install the latest version it may be fixed.

As an aside, you may want to change node versions to node 14 (or even 12) as you could potentially run into issues with node 15.

It seems truffle compiler is broken. It cannot even read the pragma directive in the code. and I clearly wrote it in the code.