metaplex-foundation / umi

A Solana Framework for JS Clients.
https://umi.typedoc.metaplex.com
MIT License
161 stars 48 forks source link

Unable to resolve "@metaplex-foundation/umi/serializers" from "node_modules/@metaplex-foundation/mpl-bubblegum/dist/src/hash.js" #94

Open mordonez-me opened 11 months ago

mordonez-me commented 11 months ago

No clue about what is going here...

Libraries

"@metaplex-foundation/umi": "^0.8.9",
"@metaplex-foundation/umi-bundle-defaults": "^0.8.9",
"@metaplex-foundation/umi-serializers": "^0.8.9",
"@metaplex-foundation/umi-web3js-adapters": "^0.8.9",

Code: image

Stacktrace:

Unable to resolve module @metaplex-foundation/umi/serializers from FULLPATH/node_modules/@metaplex-foundation/mpl-bubblegum/dist/src/hash.js: @metaplex-foundation/umi/serializers could not be found within the project or in these directories:
  node_modules/@metaplex-foundation/mpl-bubblegum/node_modules
  node_modules
  2 | Object.defineProperty(exports, "__esModule", { value: true });
  3 | exports.hashMetadataCreators = exports.hashMetadataData = exports.hashMetadata = exports.hashLeaf = exports.hash = void 0;
> 4 | const serializers_1 = require("@metaplex-foundation/umi/serializers");
    |                                ^
  5 | const sha3_1 = require("@noble/hashes/sha3");
  6 | const generated_1 = require("./generated");
  7 | const leafAssetId_1 = require("./leafAssetId");
mordonez-me commented 11 months ago

This is everywhere

image

gmferraz commented 11 months ago

@mordonez-me any updates? Facing the same issue

mordonez-me commented 11 months ago

I just patched everywhere image

Could you let me know if you found the error? I can try again if it's fixed, lmk.

truongezgg commented 8 months ago

I got the same error when trying to test my module by use jest. But it work with ts-node

ts-node metadata.spec.ts (success) npm run test medata.spec.ts (Unable to resolve "@metaplex-foundation/umi/serializers" from...)

Michaelsulistio commented 6 months ago

Ran into this issue on React Native and after some investigation might have found the root cause.

Cause

This issue is caused because the @metaplex-foundation/umi package uses Package Exports to export the umi/serializers submodule.

React Native's Metro Bundler doesn't support Package Exports by default, so it is unable to find umi/serializers. Currently, Package Exports are an experimental feature in Metro and can be enabled following this guide.

Attempted fix

Following the guide, I enabled the experimental unstable_enablePackageExports flag, which actually fixed the issues with @metaplex-foundation/umi/serializers and the bundler was able to find it.

This is what I added to metro.config.js:

module.exports = {
  ...
  resolver: {
    unstable_enablePackageExports: true,
    unstable_conditionNames: ['types', 'require', 'import'],
  },

But it ran into another issue when trying to resolve an import within umi-bundle-defaults.

Error: Unable to resolve module ./plugin from /Users/mikesulistio/testing/umi-testing/UmiTestRN/node_modules/@metaplex-foundation/umi-bundle-defaults/dist/types/index.d.ts: 
nhanphan commented 6 months ago

enabling the unstable_enablePackageExports without specifying unstable_conditionNames made my test app build.

module.exports = {
  ...
  resolver: {
    unstable_enablePackageExports: true,
  },

Find the bare bones app that can build here. NOTE: the button doesn't actually create an asset since it's expecting crypto to be there but the imports seem to be working as expected

MarkSackerberg commented 3 months ago

As an additional workaround for node.js express @Gin on Discord shared that this worked for them:

const moduleAlias = require('module-alias');
moduleAlias.addAlias('@metaplex-foundation/umi/serializers', '@metaplex-foundation/umi-serializers');