Skip to content

TypeError: changes is undefined #1767

Description

@dmag-vivlio

hello this is the first time I decided to try and make a contribution to any big project, feel free to point out any mistakes I may be making in the code or in the opening of this issue, I want to learn.

I recently noticed that my metro runner was crashing because the value of changes was undefined and being used unsafely in two separate methods.

Error 1

node_modules/@react-native/community-cli-plugin/node_modules/metro/src/node-haste/DependencyGraph.js:99
    ...changes.addedFiles,
^

TypeError: Cannot read properties of undefined (reading 'addedFiles')
    at DependencyGraph.\_onHasteChange (node_modules/@react-native/community-cli-plugin/node_modules/metro/src/node-haste/DependencyGraph.js:99:18)
    at FileMap.<anonymous> (node_modules/@react-native/community-cli-plugin/node_modules/metro/src/node-haste/DependencyGraph.js:68:14)
    at FileMap.emit (node:events:536:35)
    at Object.onChange (node_modules/react-native-css-interop/dist/metro/index.js:179:19)
    at ChildProcess.<anonymous> (node_modules/nativewind/dist/metro/tailwind/v3/index.js:51:37)
    at ChildProcess.emit (node:events:524:28)
    at emit (node:internal/child_process:950:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

Error 2

node_modules/metro/src/DeltaBundler/DeltaCalculator.js:114
    for (const [canonicalPath, metadata] of changes.addedFiles) {
                                                    ^

TypeError: Cannot read properties of undefined (reading 'addedFiles')
    at FileMap._handleMultipleFileChanges (node_modules/metro/src/DeltaBundler/DeltaCalculator.js:114:53)
    at FileMap.emit (node:events:536:35)
    at Object.onChange (node_modules/react-native-css-interop/dist/metro/index.js:179:19)
    at ChildProcess.<anonymous> (node_modules/nativewind/dist/metro/tailwind/v3/index.js:51:37)
    at ChildProcess.emit (node:events:524:28)
    at emit (node:internal/child_process:950:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

I locally applied changes to these methods to check the value of changes before trying to work with them, I will attack the patch I used locally to this issue.

Please do tell me if a better fix could be done.
I would love to contribute and open a pull request but I am not sure if my code is an appropriately good fix for this issue.

metro-npm-0.84.4-6f2a1c8e3b.patch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions