bytecodealliance / ComponentizeJS

JS -> WebAssembly Component
Apache License 2.0
242 stars 32 forks source link

"Cannot find module" error #20

Closed manuel closed 1 year ago

manuel commented 1 year ago

I tried running the example https://github.com/bytecodealliance/componentize-js/blob/main/EXAMPLE.md but got the error:

$ node -e "import('./hello/hello.component.js').then(m => console.log(m.hello('ComponentizeJS')))"
node:internal/errors:465
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/mjs/tmp/comp/node_modules/@bytecodealliance/preview2-shim/lib/nodejs/wall-clock' imported from /home/mjs/tmp/comp/hello/hello.component.js
    at new NodeError (node:internal/errors:372:5)
    at finalizeResolution (node:internal/modules/esm/resolve:437:11)
    at moduleResolve (node:internal/modules/esm/resolve:1009:10)
    at defaultResolve (node:internal/modules/esm/resolve:1218:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
    at link (node:internal/modules/esm/module_job:78:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

I then manually changed the start of the file hello/hello.component.js to directly refer to the libraries, and it worked:

import { now as lowering12Callee, resolution as lowering13Callee } from '../node_modules/@bytecodealliance/preview2-shim/lib/nodejs/wall-clock.js';
import { getRandomBytes as lowering21Callee } from '../node_modules/@bytecodealliance/preview2-shim/lib/nodejs/random.js';
import { getStdio as lowering10Callee, getDirectories as lowering11Callee } from '../node_modules/@bytecodealliance/preview2-shim/lib/nodejs/preopens.js';
import { resolution as lowering0Callee, now as lowering1Callee } from '../node_modules/@bytecodealliance/preview2-shim/lib/nodejs/monotonic-clock.js';
import { exit as lowering7Callee } from '../node_modules/@bytecodealliance/preview2-shim/lib/nodejs/exit.js';
import { dropInputStream as lowering8Callee, dropOutputStream as lowering9Callee, read as lowering23Callee, write as lowering24Callee } from '../node_modules/@bytecodealliance/preview2-shim/lib/nodejs/streams.js';
import { getEnvironment as lowering22Callee } from '../node_modules/@bytecodealliance/preview2-shim/lib/nodejs/environment.js';
import { dropDirectoryEntryStream as lowering2Callee, readViaStream as lowering3Callee, writeViaStream as lowering4Callee, appendViaStream as lowering5Callee, dropDescriptor as lowering6Callee, getFlags as lowering14Callee, getType as lowering15Callee, setFlags as lowering16Callee, stat as lowering17Callee, openAt as lowering18Callee, removeDirectoryAt as lowering19Callee, unlinkFileAt as lowering20Callee } from '../node_modules/@bytecodealliance/preview2-shim/lib/nodejs/filesystem.js';
guybedford commented 1 year ago

Thanks for posting the issue, the preview2 bindings are changing a lot still unfortunately. I've just released a componentize-js@0.0.6 which should resolve the issue. There is also a new example folder in https://github.com/bytecodealliance/componentize-js/tree/main/example that provides exact version revisions for preview2 builds.