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

Bundler workers are not exported from package anymore #3034

Open
kouak opened this issue Jun 25, 2024 · 1 comment
Open

Bundler workers are not exported from package anymore #3034

kouak opened this issue Jun 25, 2024 · 1 comment

Comments

@kouak
Copy link
Contributor

kouak commented Jun 25, 2024

I'm using deck.gl with @loaders.gl/mvt for an internal app, in an offline/airgapped environment. Browsers are not connected to the internet and can't load the worker bundle from unpkg.com.

I used to import the worker bundle with a custom webpack config and the following statement :

// Deck.tsx
import mvtLoaderWorkerUrl from '@loaders.gl/mvt/dist/mvt-worker.js';

// webpack.config.ts
            {
              test: [/dist\/mvt-worker\.js$/],
              type: 'asset/resource',
              generator: {
                filename: 'mvt-worker.[hash].js',
              },
            }

For reference, here's a similar implementation with vite (no special config) :

import mvtLoaderWorkerUrl from '@loaders.gl/mvt/dist/mvt-worker.js?url';

With @loaders.gl/mvt v4.2.2, I'm encountering this error :

Module not found: Error: Package path ./dist/mvt-worker.js is not exported from package <appDir>/frontend/node_modules/@loaders.gl/mvt (see exports field in <appDir>/frontend/node_modules/@loaders.gl/mvt/package.json)

A workaround is to import the file via relative import

import mvtLoaderWorkerUrl from '../../../../node_modules/@loaders.gl/mvt/dist/mvt-worker.js';

I guess a solution would be to include the bundled worker.js file in the package.json#exports field:

{
 "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.js",
      "require": "./dist/index.cjs"
    },
    "./dist/mvt-worker.js": {
      "import": "./dist/mvt-worker.js"
    }
  }
}

I'm currently having this issue with @loaders.gl/mvt because that's the one I'm using, but AFAIK, this issue should affect all other loaders.

@ibgreen
Copy link
Collaborator

ibgreen commented Jun 25, 2024

Yes this seems like a side effect of introducting the "exports" section in package.json.

It would probably be OK to add an export field for the workers. Maybe even skip the dist?

`{
"exports": {
".": {...},
"./mvt-worker.js": {
"import": "./dist/mvt-worker.js"
}
}
}

Feel free to open a PR on the mvt module. We can do this module by module for now and do a pass on all modules once the idea is proven.

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