peter-murray / node-hue-api

Node.js Library for interacting with the Philips Hue Bridge and Lights
Apache License 2.0
1.18k stars 144 forks source link

Error when using Webpack / Electron #216

Closed chrisle closed 2 years ago

chrisle commented 2 years ago

I'm not really sure what's happening. It seems that there's something going on when Webpack tries to bundle my Electron app with the latest version of node-hue-api. Anyone have any ideas?

For context, I used the Electron React Boilerplate with Typescript.

https://github.com/electron-react-boilerplate/electron-react-boilerplate

> postinstall
> ts-node .erb/scripts/check-native-dep.js && electron-builder install-app-deps && cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.dev.dll.ts && opencollective-postinstall

  • electron-builder  version=22.14.5
  • loaded configuration  file=package.json ("build" field)
  • installing production dependencies  platform=darwin arch=x64 appDir=/Users/chrisle/code/nowplaying2/release/app
ERROR in ./node_modules/node-hue-api/dist/esm/index.js 4:0-45
Module not found: Error: Can't resolve './api/discovery' in '/Users/chrisle/code/nowplaying2/node_modules/node-hue-api/dist/esm'
Did you mean 'index.js'?
BREAKING CHANGE: The request './api/discovery' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ dll renderer renderer[26]
chrisle commented 2 years ago

Well I at least tracked it down to the fact that the post-install was using webpack. My tsconfig modules was set to "commonjs" but for some reason, webpack was trying to use the ESM version in node-hue-api.

I don't know how to configure webpack to deal with TypeScript and CJS so my solution is to use the 4.x branch which is written in JavaScript instead of TypeScript.