smapiot / piral

🚀 Framework for next generation web apps using micro frontends. ⭐️ Star to support our work!
https://piral.io
MIT License
1.68k stars 125 forks source link

CLI: Handle Absence of `devDependencies` in `package.json` Files #639

Closed manuelroemer closed 11 months ago

manuelroemer commented 11 months ago

New Pull Request

For more information, see the CONTRIBUTING guide.

Prerequisites

Please make sure you can check the following boxes:

Type(s) of Changes

Contribution Type

What types of changes does your code introduce? Put an x in all the boxes that apply:

Description

We were running into an issue where the pilet build ... command failed building the pimon-portal sample project on the newest Piral version (1.3.2) on Windows. The output was simply:

npm run start:fe:pilets

> start:fe:pilets
> pilet debug packages/frontend/*-pilet

+ piral-cli v1.3.2
⠋ Reading configuration ...
TypeError: Cannot read properties of undefined (reading '@emotion/react')

It seems that the error originated from the lack of a devDependencies section in the project's app shell package. Adding this section with an empty record {} makes the build work again.

I traced the error down by adding logs to the CLI's JS files and got this stack trace:

TypeError: Cannot read properties of undefined (reading '@emotion/react')
    at getDependencyDetails (C:\Development\smapiot\Piral\pimon-portal\node_modules\piral-cli\lib\common\importmap.js:56:39)
    at C:\Development\smapiot\Piral\pimon-portal\node_modules\piral-cli\lib\common\importmap.js:137:71
    at Generator.next (<anonymous>)
    at C:\Development\smapiot\Piral\pimon-portal\node_modules\piral-cli\lib\common\importmap.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (C:\Development\smapiot\Piral\pimon-portal\node_modules\piral-cli\lib\common\importmap.js:4:12)
    at resolveImportmap (C:\Development\smapiot\Piral\pimon-portal\node_modules\piral-cli\lib\common\importmap.js:119:12)
    at C:\Development\smapiot\Piral\pimon-portal\node_modules\piral-cli\lib\common\importmap.js:268:22
    at Generator.next (<anonymous>)
    at C:\Development\smapiot\Piral\pimon-portal\node_modules\piral-cli\lib\common\importmap.js:8:71 TypeError: Cannot read properties of undefined (reading '@emotion/react')
    at getDependencyDetails (C:\Development\smapiot\Piral\pimon-portal\node_modules\piral-cli\lib\common\importmap.js:56:39)
    at C:\Development\smapiot\Piral\pimon-portal\node_modules\piral-cli\lib\common\importmap.js:137:71
    at Generator.next (<anonymous>)
    at C:\Development\smapiot\Piral\pimon-portal\node_modules\piral-cli\lib\common\importmap.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (C:\Development\smapiot\Piral\pimon-portal\node_modules\piral-cli\lib\common\importmap.js:4:12)
    at resolveImportmap (C:\Development\smapiot\Piral\pimon-portal\node_modules\piral-cli\lib\common\importmap.js:119:12)
    at C:\Development\smapiot\Piral\pimon-portal\node_modules\piral-cli\lib\common\importmap.js:268:22
    at Generator.next (<anonymous>)
    at C:\Development\smapiot\Piral\pimon-portal\node_modules\piral-cli\lib\common\importmap.js:8:71

...which makes me think that adding the fallback in this PR could solve the issue. By using a devDependencies fallback of {}, availableSpecs is not undefined and should then not cause the error in resolveImportmap > getDependencyDetails.

Remarks

None.

github-actions[bot] commented 11 months ago

File size impact

Merging fix/cli-error-on-missing-dev-dependencies-on-win32 into develop impact files as follow:

empty-piral (no impact)
Files new size
Unmodified (2) 29.1 kB (0 B / +0%) :ghost:
Total (2) 29.1 kB (0 B / +0%) :ghost:
minimal-piral (no impact)
Files new size
Unmodified (2) 254 kB (0 B / +0%) :ghost:
Total (2) 254 kB (0 B / +0%) :ghost:
sample-cross-fx (no impact)
Files new size
Unmodified (3) 2.26 MB (0 B / +0%) :ghost:
Total (3) 2.26 MB (0 B / +0%) :ghost:
sample-piral (no impact)
Files new size
Unmodified (3) 645 kB (0 B / +0%) :ghost:
Total (3) 645 kB (0 B / +0%) :ghost:
sample-piral-core (no impact)
Files new size
Unmodified (3) 308 kB (0 B / +0%) :ghost:
Total (3) 308 kB (0 B / +0%) :ghost:

Generated by @jsenv/file-size-impact during check-bundle-size#6656689626 on d7f2633