Giter Site home page Giter Site logo

parcel-bug-worker-node-external-modules's Introduction

This repo contains three similar versions of a code snippet from the comlink library, specifically the node example.

This example seems to have two major issues when used in a fairly straightforward manner.

Note that my ultimate goal is to publish a single build of a library that transparently creates a worker regardless of whether it's run in node or the browser, so any node-specific fixes will not work.

Original code

This is what we are trying to mimic in source code to be processed by Parcel:

> cd node_modules/comlink/docs/examples/06-node-example
> node main.mjs

4

Issue 1: External modules

> cd issue1
> npm install
> npx parcel build src/main.ts

๐Ÿšจ Build failed.
@parcel/packager-js: External modules are not supported when building for browser
/Users/lgarron/parcel-bug-worker-node-external-modules/issue1/src/worker.ts:1:1
> 1 | import * as Comlink from "comlink";
>   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2 | import nodeEndpoint from "comlink/dist/esm/node-adapter";
  3 | import { parentPort } from "worker_threads";

Note that package.json sets "context": "node" (not "browser").

Issue 2: Origin not found

This differs from the code for issue 1 as follows:

  • "includeNodeModules": true is set for the node target in package.json. (This is not appropriate for library builds, but it allows us to demonstrate the second issue.)

Output:

> cd issue2
> npm install
> npx parcel build src/main.ts
> node dist/index.js

(node:17465) UnhandledPromiseRejectionWarning: Error: Origin not found
    at Object.L [as getOrigin] (/Users/lgarron/parcel-bug-worker-node-external-modules/issue2/dist/index.js:1:3467)
    at k (/Users/lgarron/parcel-bug-worker-node-external-modules/issue2/dist/index.js:1:3708)
    at P (/Users/lgarron/parcel-bug-worker-node-external-modules/issue2/dist/index.js:1:3873)
    at /Users/lgarron/parcel-bug-worker-node-external-modules/issue2/dist/index.js:1:10995
    at s (/Users/lgarron/parcel-bug-worker-node-external-modules/issue2/dist/index.js:1:4954)
    at Generator._invoke (/Users/lgarron/parcel-bug-worker-node-external-modules/issue2/dist/index.js:1:4707)
    at Generator.forEach.t.<computed> [as next] (/Users/lgarron/parcel-bug-worker-node-external-modules/issue2/dist/index.js:1:5311)
    at G (/Users/lgarron/parcel-bug-worker-node-external-modules/issue2/dist/index.js:1:10554)
    at i (/Users/lgarron/parcel-bug-worker-node-external-modules/issue2/dist/index.js:1:10757)
    at /Users/lgarron/parcel-bug-worker-node-external-modules/issue2/dist/index.js:1:10816
(Use `node --trace-warnings ...` to show where the warning was created)
(node:17465) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:17465) [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.

Note that building with npx parcel build --public-url . src/main.ts produces the same result.

parcel-bug-worker-node-external-modules's People

Contributors

lgarron avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.