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

Build fails when a service has a nodejs dependency in a sub-folder #1450

Open
paultranvan opened this issue Mar 9, 2022 · 0 comments
Open

Comments

@paultranvan
Copy link
Contributor

paultranvan commented Mar 9, 2022

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:

servicesPaths.forEach(file => {
if (!file.match(/^[^.]*.js$/)) return
var filename = file.match(/^([^.]*).js$/)[1]
servicesEntries[filename] = path.resolve(path.join(servicesFolder, file))
})

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:

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?

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

1 participant