AcalaNetwork / chopsticks

Create parallel reality of your Substrate network.
Apache License 2.0
134 stars 80 forks source link

ESM issues when upgrading to 9.0.0 #510

Closed goncer closed 10 months ago

goncer commented 11 months ago

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 commented 11 months ago

@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 commented 11 months ago

@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 commented 11 months ago

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

goncer commented 11 months ago

It fails when running the tests.. :s

ermalkaleci commented 11 months ago

tried your repo and was able to reproduce

qiweiii commented 11 months ago

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 commented 11 months ago

could be related: https://github.com/jestjs/jest/issues/11563

ermalkaleci commented 10 months ago

@goncer can you try 0.9.1-2

goncer commented 10 months ago

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