Skip to content

Cannot find module '../openzeppelin-contracts' from 'node_modules/@openzeppelin/wizard/dist/get-versioned-remappings.js' #734

@ericglau

Description

@ericglau

In the latest version of @openzeppelin/wizard and @openzeppelin/contracts-mcp, attempting to use these packages as a dependency causes the following error:

    Cannot find module '../openzeppelin-contracts' from 'node_modules/@openzeppelin/wizard/dist/get-versioned-remappings.js'

    Require stack:
      node_modules/@openzeppelin/wizard/dist/get-versioned-remappings.js
      node_modules/@openzeppelin/wizard/dist/api.js
      node_modules/@openzeppelin/wizard/dist/index.js
      node_modules/@openzeppelin/contracts-mcp/dist/solidity/tools/account.js
      node_modules/@openzeppelin/contracts-mcp/dist/solidity/tools.js
      node_modules/@openzeppelin/contracts-mcp/dist/index.js
      app/contracts/solidity/[transport]/route.ts
      __tests__/contracts/solidity.test.ts

Full log is here: https://github.com/OpenZeppelin/openzeppelin-mcp/actions/runs/19337851749/job/55317829277

This occurs because in #724, packages/core/solidity/src/get-versioned-remappings.ts uses the version field from packages/core/solidity/openzeppelin-contracts.json, but this JSON file is not included in the NPM package.

We should NOT include the entire JSON file, because most of its contents is just OpenZeppelin Contracts source code and is not necessary for the API/MCP. Including that file would just make the NPM package unnecessarily large.

The proper fix should be:

  1. In packages/core/solidity/src/scripts/prepare.ts, when it generates openzeppelin-contracts.json, add a step to also generate a separate file containing only the version field. This can be a minimal json file, for example openzeppelin-contracts-version.json with only the following contents:
{
  "version": "5.5.0"
}
  1. Add a file similar to packages/core/solidity/openzeppelin-contracts.d.ts with only the version field. This is used for the types.
  2. Update packages/core/solidity/src/get-versioned-remappings.ts to get the version from the new file instead of openzeppelin-contracts.
  3. Update the files entry in packages/core/solidity/package.json to include the new json file in the package.
  4. Run yarn changeset to add a patch change for @openzeppelin/wizard

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions