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

full.render.js is broken on Realese 2.1.1 #160

Closed
zetaraku opened this issue Nov 30, 2018 · 4 comments
Closed

full.render.js is broken on Realese 2.1.1 #160

zetaraku opened this issue Nov 30, 2018 · 4 comments

Comments

@zetaraku
Copy link

The error message is Identifier 'error' has already been declared
since error is already declared in the catch clause.

full.render.js

if (typeof importScripts === "function") {
  var instance = Module();
  
  onmessage = function(event) {
    var id = event.data.id;
    var src = event.data.src;
    var options = event.data.options;
  
    try {
      var result = render(instance, src, options);
      postMessage({ id: id, result: result });
    } catch (error) {
<<<<<<< v2.0.0
      postMessage({ id: id, error: { message: error.message, fileName: error.fileName, lineNumber: error.lineNumber } });
=======
      var error = error instanceof Error
        ? { message: error.message, fileName: error.fileName, lineNumber: error.lineNumber }
        : { message: error.toString() };
      postMessage({ id: id, error: error });
>>>>>>> v2.1.1
    }
  }
}
mdaines added a commit that referenced this issue Dec 2, 2018
@mdaines
Copy link
Owner

mdaines commented Dec 2, 2018

In what environment and situation are you seeing this? I think the referenced commit should address it, but knowing that might help prevent similar mistakes in the future.

@zetaraku
Copy link
Author

zetaraku commented Dec 2, 2018

I was using viz.js for my project with webpack, and it gave me the error message (shown below) when packing my project.

ERROR in ./node_modules/viz.js/full.render.js 68:10
Module parse failed: Identifier 'error' has already been declared (68:10)
You may need an appropriate loader to handle this file type.
|       postMessage({ id: id, result: result });
|     } catch (error) {
>       var error = error instanceof Error
|         ? { message: error.message, fileName: error.fileName, lineNumber: error.lineNumber }
|         : { message: error.toString() };
 @ ./src/js/main/index.js 30:0-52 46:22-28 46:30-36
 @ ./src/index.js

@mdaines
Copy link
Owner

mdaines commented Dec 5, 2018

v2.1.2-pre.1 (also on NPM) includes a fix for this.

It looks like you're importing the render script file. You can certainly do that, and I've added an example showing that technique. It fails to build with v2.1.1 (in the way you're seeing) and works with v2.1.2-pre.1.

However, if possible I would recommend something like this example, where file-loader imports just the URL of the render script file using the ".render.js" suffix and then passes that to the Viz constructor:

https://github.com/mdaines/viz-examples/blob/0a9f7100aa73ff6f4ec4b4e150a842033a058ade/webpack/index.js#L2-L4

This avoids having Webpack actually look at the contents of the render script file, which is pretty big and will slow down the build.

@zetaraku
Copy link
Author

zetaraku commented Dec 6, 2018

Thanks for the quick fix and the suggestion and explanation of using file-loader! :D
My project now works fine!

Since the render script is a special case for the .js files, I use:
import vizjsWorkerURL from 'file-loader!viz.js/full.render.js';
to import it instead. :)

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

2 participants