Error: ASTDereferencerError: No node with id 6677 of type ContractDefinition

I am facing the error: ASTDereferencerError: No node with id 6677 of type ContractDefinition while deploying the upgradeable contract using the truffle upgrades.

I tried removing build directory, reinstalling the truffle and ganache, clean checking out the project. but didn`t worked anything.

Any help would be appreciated.

here, is the migration script I am using

const name = 'Marketplace';
const contract = artifacts.require(name);

module.exports = async (deployer, network, accounts) => {
	try {
		const networkId = deployer.network_id.toString();
		const deployedContract = await deployProxy(contract, [FeeReceiver, ServiceFee], {
			deployer,
			initializer: 'initialize'
		});
		console.log('NftMarketplaceWithRoyalty Address: ', deployedContract.address);
	} catch (error) {
		console.log('error: ', error);
	}
};

I am using below dependencies for the project-

"dependencies": {
    "@openzeppelin/contracts": "^4.9.3",
    "@openzeppelin/contracts-upgradeable": "^4.9.3",
    "@openzeppelin/test-helpers": "^0.5.16",
    "@openzeppelin/truffle-upgrades": "^1.20.0",
    "@truffle/hdwallet-provider": "^2.1.13",
    "chai": "^4.3.7",
    "child_process": "^1.0.2",
    "eslint": "^8.47.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-prettier": "^5.0.0",
    "eth-gas-reporter": "^0.2.25",
    "fs": "^0.0.1-security",
    "ganache": "^7.9.0",
    "ganache-cli": "^6.12.2",
    "husky": "^8.0.3",
    "lcov2badge": "^0.1.2",
    "path": "^0.12.7",
    "prettier": "^3.0.2",
    "solidity-coverage": "^0.8.4",
    "solidity-docgen": "^0.6.0-beta.35",
    "truffle-contract-size": "^2.0.1",
    "truffle-plugin-verify": "^0.6.5"
  },

:computer: Environment

Truffle v5.11.2 (core: 5.11.2)
Ganache v7.9.0
Solidity - ^0.8.0 (solc-js)
Node v16.13.0
Web3.js v1.10.0

Could you provide either the information listed in Required information when requesting support for Upgrades Plugins, or share your project so that we can see how it is set up?

If there is any stacktrace or other output when the error occurs, can you provide that as well?

Here is the info related with above issue

  1. Debug logs
error:  ASTDereferencerError: No node with id 6677 of type ContractDefinition
    at deref (/home/Documents/Projects/nft-marketplace/node_modules/solidity-ast/src/ast-dereferencer.ts:59:11)
    at derefNode (/home/Documents/Projects/nft-marketplace/node_modules/solidity-ast/src/ast-dereferencer.ts:63:12)
    at curried (/home/Documents/Projects/nft-marketplace/node_modules/solidity-ast/src/ast-dereferencer.ts:84:14)
    at getInheritedContractOpcodeErrors (/home/Documents/Projects/nft-marketplace/node_modules/@openzeppelin/upgrades-core/src/validate/run.ts:361:34)
    at getInheritedContractOpcodeErrors.next (<anonymous>)
    at getContractOpcodeErrors (/home/Documents/Projects/nft-marketplace/node_modules/@openzeppelin/upgrades-core/src/validate/run.ts:254:10)
    at getContractOpcodeErrors.next (<anonymous>)
    at getOpcodeErrors (/home/Documents/Projects/nft-marketplace/node_modules/@openzeppelin/upgrades-core/src/validate/run.ts:229:10)
    at getOpcodeErrors.next (<anonymous>)
    at validate (/home/Documents/Projects/nft-marketplace/node_modules/@openzeppelin/upgrades-core/src/validate/run.ts:167:14)
    at validateArtifacts (/home/Documents/Projects/nft-marketplace/node_modules/@openzeppelin/truffle-upgrades/src/utils/validations.ts:21:18)
    at getDeployData (/home/Documents/Projects/nft-marketplace/node_modules/@openzeppelin/truffle-upgrades/src/utils/deploy-impl.ts:41:23)
    at deployProxyImpl (/home/Documents/Projects/nft-marketplace/node_modules/@openzeppelin/truffle-upgrades/src/utils/deploy-impl.ts:64:22)
    at deployProxy (/home/Documents/Projects/nft-marketplace/node_modules/@openzeppelin/truffle-upgrades/src/deploy-proxy.ts:36:26)
    at module.exports (/home/Documents/Projects/nft-marketplace/migrations/4_deploy_nft_marketplace_royalty.js:18:24) {
  id: 6677,
  nodeType: [ 'ContractDefinition' ]
}
  1. Truffle Configs
/* eslint-disable camelcase */
/**
 * Use this file to configure your truffle project. It's seeded with some
 * common settings for different networks and features like migrations,
 * compilation and testing. Uncomment the ones you need or modify
 * them to suit your project as necessary.
 *
 * More information about configuration can be found at:
 *
 * trufflesuite.com/docs/advanced/configuration
 *
 * To deploy via Infura you'll need a wallet provider (like @truffle/hdwallet-provider)
 * to sign your transactions before they're sent to a remote public node. Infura accounts
 * are available for free at: infura.io/register.
 *
 * You'll also need a mnemonic - the twelve word phrase the wallet uses to generate
 * public/private key pairs. If you're publishing your code to GitHub make sure you load this
 * phrase from a file you've .gitignored so it doesn't accidentally become public.
 *
 */

const {
	mnemonic,
	BSCSCAN_API_KEY,
	ETHERSCAN_API_KEY,
	POLYSCAN_API_KEY,
	infuraApiKey
} = require('./secrets.json');
const test_data = require('./secrets.test.json');
const HDWalletProvider = require('@truffle/hdwallet-provider');

module.exports = {
	plugins: ['solidity-coverage', 'truffle-plugin-verify', 'truffle-contract-size'],
	api_keys: {
		bscscan: BSCSCAN_API_KEY,
		etherscan: ETHERSCAN_API_KEY,
		polygonscan: POLYSCAN_API_KEY
	},
	contracts_directory: './contracts/',
	/**
	 * Networks define how you connect to your ethereum client and let you set the
	 * defaults web3 uses to send transactions. If you don't specify one truffle
	 * will spin up a development blockchain for you on port 9545 when you
	 * run `develop` or `test`. You can ask a truffle command to use a specific
	 * network from the command line, e.g
	 *
	 * $ truffle test --network <network-name>
	 */
	networks: {
		// Useful for testing. The `development` name is special - truffle uses it by default
		// if it's defined here and no other network is specified at the command line.
		// You should run a client (like ganache-cli, geth or parity) in a separate terminal
		// tab if you use this network and you must also set the `host`, `port` and `network_id`
		// options below to some value.
		development: {
			host: '127.0.0.1', // Localhost (default: none)
			port: 8545, // Standard Ethereum port (default: none)
			network_id: '*' // Any network (default: none)
		},
		coverage: {
			host: 'localhost',
			network_id: 1111,
			port: 8555,
			gas: 8000000,
			gasPrice: 1000000000
		},
		local_fork: {
			port: 8545,
			network_id: 9999, // Custom network
			gas: 20000000000, // Gas sent with each transaction (default: ~6700000)
			gasPrice: 20000000000, // 20 gwei (in wei) (default: 100 gwei)
			websocket: true // Enable EventEmitter interface for web3 (default: false)
		},
		bsc_test: {
			provider: () =>
				new HDWalletProvider(test_data.mnemonic, 'https://data-seed-prebsc-1-s1.binance.org:8545/'),
			gasPrice: 10000000000, // 10 gwei (in wei)
			network_id: 97,
			timeout: 20000000,
			skipDryRun: true,
			networkCheckTimeout: 20000000
		},
		bsc_main: {
			provider: () => new HDWalletProvider(mnemonic, 'https://bsc-dataseed1.ninicoin.io'),
			network_id: 56,
			gasPrice: 10000000000, // 10 gwei (in wei)
			skipDryRun: true
		},
		mumbai: {
			provider: () => new HDWalletProvider(mnemonic, 'https://rpc-mumbai.maticvigil.com/'),
			network_id: 80001,
			gasPrice: 10e9,
			skipDryRun: true,
			networkCheckTimeout: 20000000
		},
		matic: {
			provider: () => new HDWalletProvider(mnemonic, 'https://matic-mainnet.chainstacklabs.com/'),
			// https://rpc-mumbai.maticvigil.com/
			// https://matic-mumbai.chainstacklabs.com
			// https://rpc-mumbai.matic.today
			network_id: 137,
			gasPrice: 10e9,
			skipDryRun: true,
			timeout: 20000000,
			networkCheckTimeout: 20000000,
			timeoutBlocks: 200
		}
		// Useful for deploying to a public network.
		// NB: It's important to wrap the provider as a function.
		// ropsten: {
		// provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`),
		// network_id: 3,       // Ropsten's id
		// gas: 5500000,        // Ropsten has a lower block limit than mainnet
		// confirmations: 2,    // # of confs to wait between deployments. (default: 0)
		// timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)
		// skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )
		// },
		// Useful for private networks
		// private: {
		// provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
		// network_id: 2111,   // This network is yours, in the cloud.
		// production: true    // Treats this network as if it was a public net. (default: false)
		// }
	},

	// Set default mocha options here, use special reporters etc.
	mocha: {
		timeout: 10000000,
		useColors: true,
		slow: 30000,
		bail: true,
		reporter: 'eth-gas-reporter',
		reporterOptions: {
			excludeContracts: ['Migrations', 'mocks'],
			currency: 'USD',
			noColors: true
		}
	},

	// Configure your compilers
	compilers: {
		solc: {
			version: '0.8.18', // Fetch exact version from solc-bin (default: truffle's version)
			// docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
			settings: {
				// See the solidity docs for advice about optimization and evmVersion
				optimizer: {
					enabled: true,
					runs: 1
				}
				// evmVersion: "byzantium"
			}
		}
	}
};

  1. Truffle version
Truffle v5.4.5 (core: 5.4.5)
Solidity - 0.8.18 (solc-js)
Node v18.1.0
Web3.js v1.5.1
  1. Migration command
npx truffle migrate --network=mumbai

Can you share everything we need to reproduce the error? This includes the Solidity code. The entire project ideally.

There is a chance that this is due to Truffle limitations that we have to work around, and there may not be a fix other than using Hardhat.