Skip to content

Comments

[FIX] single export TypeError: cannot read properties error#43

Open
debdutdeb wants to merge 1 commit intoRocketChat:masterfrom
debdutdeb:fix/41-single-export
Open

[FIX] single export TypeError: cannot read properties error#43
debdutdeb wants to merge 1 commit intoRocketChat:masterfrom
debdutdeb:fix/41-single-export

Conversation

@debdutdeb
Copy link
Member

@debdutdeb debdutdeb commented Jan 6, 2022

closes #41

@debdutdeb debdutdeb force-pushed the fix/41-single-export branch 3 times, most recently from 3a5b719 to e24c356 Compare January 6, 2022 08:17
Signed-off-by: Debdut Chakraborty <debdut.chakraborty@rocket.chat>
@debdutdeb debdutdeb force-pushed the fix/41-single-export branch from e24c356 to 4eef13f Compare January 6, 2022 08:18
Copy link
Member

@d-gubert d-gubert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR solves that issue, but disregards the comments in the class file:

          * However, we need to handle this case due to backwards compatibility,
          * since the main class file might export a class with an unknown name,
          * which was supported in the early versions of the Apps-Engine.

Which causes apps that don't follow the convention of naming their classes the same as their files to break.

A solution I've found to all these problems is to simply change the if statement in the compiledRequire function as follows:

        if (Object.keys(exports).length === 1 && typeof result === 'function') {
            return result;
        }

This way we are handling the older cases more specifically while fixing the problem.

The other changes are not needed.

@debdutdeb can you apply these changes to the PR? :)

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

Successfully merging this pull request may close these issues.

Fix in 0.3.1 causes import bug with module which has only 1 export

2 participants