metaplex-foundation / js

A JavaScript SDK for interacting with Metaplex's programs
357 stars 182 forks source link

Production build error #232

Closed ninnjak closed 2 years ago

ninnjak commented 2 years ago

I'm trying to create a production build but get the error below. I have no issues when using the library in local dev.

I've tried with both v0.13.2 and v0.14.0

node:internal/modules/cjs/loader:361
      throw err;
      ^

Error: Cannot find module '/app/node_modules/@metaplex-foundation/mpl-candy-machine/dist/src/mpl-candy-machine.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:353:19)
    at Function.Module._findPath (node:internal/modules/cjs/loader:566:18)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/app/node_modules/@metaplex-foundation/js/dist/cjs/plugins/candyMachineModule/createCandyMachine.cjs:5:23)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/app/node_modules/@metaplex-foundation/js/dist/cjs/plugins/candyMachineModule/CandyMachinesBuildersClient.cjs:5:26)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) {
  code: 'MODULE_NOT_FOUND',
  path: '/app/node_modules/@metaplex-foundation/mpl-candy-machine/package.json',
  requestPath: '@metaplex-foundation/mpl-candy-machine'
adteague commented 2 years ago

the dist folder does not exist, not sure how to resolve though

Screen Shot 2022-08-12 at 8 17 31 PM

EDIT: The issue is within the @metaplex-foundation/mpl-candy-machine package

davidbeard741 commented 2 years ago

I just put 4 hrs into this. and I got nothing still. not even a workaround

0xDragonfly commented 2 years ago

I got it working by uninstalling @metaples-foundation/js first. Install @metaplex-foundation/mpl-candy-machine@4.3.0 (make sure it has the dist folder in the node modules/@metaplex-foundation/mpl-candy-machine directory) Install @metaples-foundation/js again. Should be working now. Like @adteague mentioned, the dist folder is missing from 4.4.0 version of mpl-candy-machine.

Alternatively you can build mpl-candy-machine from source and use the generated dist folder from there.

ninnjak commented 2 years ago

Thank you all for the help, @0xDragonfly solution didn't work for me but pointed me in the right direction. I updated the package.json to force @metaplex-foundation/mpl-candy-machine to v4.3.0 that includes the dist folder.

{
  "dependencies": {
    "@metaplex-foundation/js": "0.14.0",
    "@solana/web3.js": "^1.52.0",
  },
  "resolutions": {
    "@metaplex-foundation/mpl-candy-machine": "4.3.0"
  }
}
adteague commented 2 years ago

@ninnjak should leave this issue open so the Metaplex team is aware of the issue and address it on their end?

lorisleiva commented 2 years ago

Hi all šŸ‘‹

Thanks for raising this. As some of you mentioned, it must be an issue with an auto-generated library missing its dist folder.

I'll investigate and publish a new patch as soon as I can.

gpaluk commented 2 years ago

Hi all šŸ‘‹

Thanks for raising this. As some of you mentioned, it must be an issue with an auto-generated library missing its dist folder.

I'll investigate and publish a new patch as soon as I can.

This happens because you automatically upgrade the version of candy machine using the ^ symbol in your dependencies, so your tests pass and then the candy machine team release an update and kaboom. šŸ’„ You just need to remove the ^ from the dependency version.

devyeshtandon commented 2 years ago

After implementing @ninnjak 's solution, I am getting error

error - ./node_modules/@metaplex-foundation/beet-solana/dist/cjs/src/beet-solana.js:20:0
Module not found: Can't resolve './gpa'

Import trace for requested module:
./node_modules/@metaplex-foundation/mpl-auction-house/dist/src/generated/accounts/AuctionHouse.js
./node_modules/@metaplex-foundation/mpl-auction-house/dist/src/generated/accounts/index.js
./node_modules/@metaplex-foundation/mpl-auction-house/dist/src/generated/index.js
./node_modules/@metaplex-foundation/mpl-auction-house/dist/src/mpl-auction-house.js
./node_modules/@metaplex-foundation/js/dist/cjs/plugins/auctionHouseModule/accounts.cjs
./node_modules/@metaplex-foundation/js/dist/cjs/index.cjs

EDIT: Had to upgrade my @metaplex-foundation/beet-solana package to 0.3.0 and it worked my package.json

{
  "dependencies": {
    "@metaplex-foundation/js": "0.14.0",
    "@solana/web3.js": "^1.52.0",
  },
  "resolutions": {
    "@metaplex-foundation/mpl-candy-machine": "4.3.0",
    "@metaplex-foundation/beet-solana": "0.3.0"
  }
}
lorisleiva commented 2 years ago

I've published a new version (0.14.1) that forces version 4.3.0 of this dependency until the package gets fixed.