create-cozy-app
create-cozy-app copied to clipboard
Build fails when a service has a nodejs dependency in a sub-folder
Suppose we have a service in targets/services/service.js
, that requires a file in targets/services/subdir/file.js
, that itself requires a nodejs dependency, e.g. fs
.
When trying to build the service with cozy-scripts through yarn watch
, an error will throw: Module not found: Error: Can't resolve 'fs'
.
This is because cozy-scripts will only consider js files in targets/services/
but not in subfolder: https://github.com/cozy/create-cozy-app/blob/4b790b81f11c5485a23ad02f7be0bc3dd5219776/packages/cozy-scripts/config/webpack.config.services.js#L15-L19
Hence, any file in subdir/
requiring a nodejs primitive will fail.
A workaround would be to recursively find any .js file in targets/services/service.js
, but I'm not sure this is the correct approach, as any file will be a new entry: https://github.com/cozy/create-cozy-app/blob/4b790b81f11c5485a23ad02f7be0bc3dd5219776/packages/cozy-scripts/config/webpack.config.services.js#L33
We met this issue with @JulienMirval when trying to use cozy-konnector-libs
in a service: https://github.com/JulienMirval/dissec_cozy/blob/ee206472c49c723af630e1d740c1e0384dc73b64/src/targets/services/helpers/model.js#L2
Any thoughts?