Solidity Compilation Error: Missing pragma or contract definition in NFT project

I’m following a blockchain tutorial for creating dynamic NFTs but ran into compilation issues when trying to build my smart contracts.

When I execute the compile command:

truffle compile

I encounter these compilation errors:

Compiling your contracts...
===========================
> Compiling ./contracts/TokenMigration.sol
> Compiling ./contracts/BasicNFT.sol
> Compiling ./contracts/RandomGenerator.sol
> Compiling ./contracts/mocks/PriceFeedMock.sol
> Compiling ./contracts/mocks/VRFMock.sol
> Compiling @chainlink/contracts/src/v0.6/VRFConsumerBase.sol

@chainlink/contracts/src/v0.6/VRFConsumerBase.sol:103:1: ParserError: Expected pragma, import directive or contract/interface/library definition.
abstract contract VRFConsumerBase is VRFRequestIDBase {
^------^

project:/contracts/BasicNFT.sol:3:1: ParserError: Source "@openzeppelin/contracts/token/ERC721/ERC721Full.sol" not found
import "@openzeppelin/contracts/token/ERC721/ERC721Full.sol";

project:/contracts/BasicNFT.sol:4:1: ParserError: Source "@openzeppelin/contracts/token/ERC721/ERC721Mintable.sol" not found
import "@openzeppelin/contracts/token/ERC721/ERC721Mintable.sol";

project:/contracts/RandomGenerator.sol:51:86: ParserError: Expected '{' but got reserved keyword 'override'
function fulfillRandomness(bytes32 requestId, uint256 randomValue) internal override {
                                                                             ^------^

Compilation failed. See above.

My project structure looks normal with all the standard directories present. Has anyone encountered similar parser errors when working with Chainlink contracts? What could be causing these compilation failures?

The errors you’re encountering stem from incompatible Solidity versions and deprecated OpenZeppelin imports. The abstract keyword wasn’t recognized in older Solidity versions, and the structure of OpenZeppelin contracts changed significantly after version 3.0. You should replace your imports for ERC721Full.sol and ERC721Mintable.sol, as they have been merged into the main ERC721 contract. Make sure to check your truffle-config.js and set a consistent Solidity version (0.8.x is preferred). Additionally, your use of the override keyword necessitates a minimum pragma version of 0.6.0. I’ve faced similar issues and found that updating both the compiler version and the import paths fixed them.

looks like youre mixing different solidity versions which is causing the mess. chainlink and openzeppelin contracts need compatible versions - try downgrading to solidity 0.6.12 or upgrade everything to 0.8.x. also those ERC721Full imports are old, use just ERC721 now