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

Consider fixing types to prevent erros when installing the package in an ESM project #1769

Open
TomasHubelbauer opened this issue Dec 30, 2023 · 6 comments

Comments

@TomasHubelbauer
Copy link

Hi, I am trying to use your project through https://www.npmjs.com/package/eufy-security-client which relies on it. I set up a new Vite project using npm create vite@latest my-react-app -- --template react and installed the package but when I run npm run build, I run into an error which says:

Failed to resolve entry for package "mqtt". The package may have incorrect main/module/exports specified in its package.json. [plugin vite:dep-pre-bundle]

I believe this might be caused by incorrectly configured types. I checked your package using https://arethetypeswrong.github.io/?p=mqtt%405.3.4 and this is the result:

image

I am not a 100 % certain, but I believe the errors reported there might be what's causing the above issue.

I wonder if these could be fixed to make the package compatible with both CJS and ESM.

@robertsLando
Copy link
Member

Could you submit a PR to fix this issue?

@mschuettlerTNG
Copy link

Our code base broke with similar errors when upgrading from 5.1.3 to 5.3.4

This might be related to
#1740
and is possibly explained by
evanw/esbuild#532 (comment)

@TomasHubelbauer
Copy link
Author

@robertsLando As far as whether I can fix this, I don't know how to. I am not able to parse the information on the site I linked well enough to be able to figure out what the supposed fix is and the thread linked by Markus goes way over my head. I've personally been in the ESM-only land for several years now so my experience with dealing with CJS has (for the most part, thankfully, but in this specific instance, unfortunately) all but vanished.

@robertsLando
Copy link
Member

@mschuettlerTNG I will give a look at this when I have some time in the meanwhile if you find a fix feel free to submit a PR

@TomasHubelbauer
Copy link
Author

BTW this happens to me when using MQTT with Vite and I was able to make the error go away with this Vite config but then ran into a runtime error instead:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      'mqtt': path.resolve(__dirname, 'node_modules/mqtt/dist/mqtt.min.js')
    }
  },
})

@robertsLando
Copy link
Member

robertsLando commented Mar 12, 2024

Hi @TomasHubelbauer , did you checked the vite example in this repo? I made it work without any additional configuration, see https://github.com/mqttjs/MQTT.js/tree/main/examples/vite-example

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

3 participants