tuananh / camaro

camaro is an utility to transform XML to JSON, using Node.js binding to native XML parser pugixml, one of the fastest XML parser around.
MIT License
556 stars 29 forks source link

Module worker.js not found when using Typescript #107

Closed jonsherrard closed 4 years ago

jonsherrard commented 4 years ago

Hi There!

This project looks so great! I love the template idea and haven't seen anything as user friendly. Bravo.

I'm not sure if Camaro is supposed to work with Typescript, it feels like it should, but perhaps, there's an issue with .wasm?

I'm getting the following error about worker.js not being found when I try and run a simple test with Jest.

I'm going to keep playing around and see if it's something to do with my Typescript workflow, but I thought I'd pop this up in case anyone else had come across and fixed this issue :)

Thanks again, all the best

J

(node:2138) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2138) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

events.js:170
      throw er; // Unhandled 'error' event
      ^
Error: Cannot find module '/Users/redacted-user/redacted/project/node_modules/camaro/worker.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:668:15)
    at Function.Module._load (internal/modules/cjs/loader.js:591:27)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Promise.resolve.then (/Users/redacted-user/redacted/project/node_modules/piscina/dist/src/worker.js:39:67)
Emitted 'error' event at:
    at EventEmitterReferencingAsyncResource.runInAsyncScope (async_hooks.js:188:21)
    at Piscina.emit (/Users/redacted-user/redacted/project/node_modules/eventemitter-asyncresource/src/index.ts:50:31)
    at Worker.worker.on (/Users/redacted-user/redacted/project/node_modules/piscina/src/index.ts:596:30)
    at Worker.emit (events.js:193:13)
    at Worker.[kOnErrorMessage] (internal/worker.js:170:10)
    at Worker.[kOnMessage] (internal/worker.js:180:37)
    at MessagePort.Worker.(anonymous function).on (internal/worker.js:113:57)
    at MessagePort.emit (events.js:193:13)
    at MessagePort.onmessage (internal/worker/io.js:73:8)
node[2138]: ../src/env.cc:963:virtual node::AsyncRequest::~AsyncRequest(): Assertion `(async_) == nullptr' failed.
 1: 0x100069fdc node::Abort() [/Users/redacted-user/.nvm/versions/node/v11.15.0/bin/node]
 2: 0x100069903 node::GetErrorSource(v8::Isolate*, v8::Local<v8::Context>, v8::Local<v8::Message>, bool*) [/Users/redacted-user/.nvm/versions/node/v11.15.0/bin/node]
 3: 0x10002c4c6 node::Environment::~Environment() [/Users/redacted-user/.nvm/versions/node/v11.15.0/bin/node]
 4: 0x1000d85d9 node::worker::Worker::~Worker() [/Users/redacted-user/.nvm/versions/node/v11.15.0/bin/node]
 5: 0x1000d86c2 node::worker::Worker::~Worker() [/Users/redacted-user/.nvm/versions/node/v11.15.0/bin/node]
 6: 0x100240917 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo*) [/Users/redacted-user/.nvm/versions/node/v11.15.0/bin/node]
 7: 0x10023fee6 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/Users/redacted-user/.nvm/versions/node/v11.15.0/bin/node]
 8: 0x10023f5e0 v8::internal::Builtin_Impl_HandleApi
const { transform } = require('camaro')

const template = [
  "newsMessage/itemSet/packageItem/newsItem",
  {
    name: "catalogRef",
  },
];

export default async (xmlString: string) => {
  try {
    const result = await transform(xmlString, template);
    return result;
  } catch (e) {
    throw new Error("Transform didn't work");
  }
};

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

tuananh commented 4 years ago

@jonsherrard sorry, it's a mistake when i prepare for the new release today. i forgot to add worker.js file to files section of package.json. i have just published the 6.0.1 to fix this. you can npm install camaro@latest to try again

also, version 6 requires node >= 12. in node 11, worker_threads module is still experimental.

jonsherrard commented 4 years ago

Thanks @tuananh! That's brilliant. All working for me :)

No need to apologise! And thank you for sorting it so quickly!

J