Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESM issues when upgrading to 9.0.0 #510

Closed
goncer opened this issue Nov 3, 2023 · 9 comments
Closed

ESM issues when upgrading to 9.0.0 #510

goncer opened this issue Nov 3, 2023 · 9 comments

Comments

@goncer
Copy link
Contributor

goncer commented Nov 3, 2023

Hey,
I'm running into issues when upgrading to 9.0.0.
first, looks like set-storage is being moved,

Error: Jest: Got error running globalSetup - /home/goncer/projects/mangata-e2e/utils/globalSetup.js, reason: [TSError: ⨯ Unable to compile TypeScript:
utils/Framework/XcmHelper.ts(6,31): error TS2307: Cannot find module '@acala-network/chopsticks-core/lib/utils/set-storage' or its corresponding type declarations.
]

and after fix it, it looks like that some exports are missing or something,

file:///home/goncer/projects/mangata-e2e/utils/Framework/XcmHelper.ts:10
import { BuildBlockMode, setupWithServer } from "@acala-network/chopsticks";
         ^^^^^^^^^^^^^^
SyntaxError: Named export 'BuildBlockMode' not found. The requested module '@acala-network/chopsticks' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@acala-network/chopsticks';
const { BuildBlockMode, setupWithServer } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)
Waiting for the debugger to disconnect...

Process finished with exit code 1

Looks like that the package is not compatible anymore with esm :(

image

@qiweiii
Copy link
Member

qiweiii commented Nov 3, 2023

@goncer, I just cloned the repo, and tried it with chopsticks v0.9.0, my vscode does not give import errors after changing import to

// /utils/Framework/XcmHelper.ts
import {
  Blockchain,
  BuildBlockMode,
  setupWithServer,
} from "@acala-network/chopsticks";
import { StorageValues } from "@acala-network/chopsticks-core";

Which script give the error here?

@ermalkaleci
Copy link
Collaborator

@goncer You are importing from lib which is now changed to cjs or esm. Whatever custom configuration you have it is pointing to wrong location

@ermalkaleci
Copy link
Collaborator

@goncer also seems like you're importing setStorage using file path. You don't need to. It's a global export

@goncer
Copy link
Contributor Author

goncer commented Nov 3, 2023

It fails when running the tests.. :s

@ermalkaleci
Copy link
Collaborator

tried your repo and was able to reproduce

@qiweiii
Copy link
Member

qiweiii commented Nov 4, 2023

Adding type: "module" could fix this issue, it lets ts-jest to load chopsticks as esm.

Another problem is that chopsticks package can only support either cjs or esm, because we use __dirname and __filename in plugins, we probably need to use a bundler for dual bundle so these can be handled

@qiweiii
Copy link
Member

qiweiii commented Nov 4, 2023

could be related: jestjs/jest#11563

@ermalkaleci
Copy link
Collaborator

@goncer can you try 0.9.1-2

@goncer
Copy link
Contributor Author

goncer commented Nov 6, 2023

Works with 0.9.1-2! 🎉
Thanks @ermalkaleci , @qiweiii
the best support ever!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants