Skip to content

Conversation

@brizental
Copy link
Contributor

Currently when attempting to import the @mozilla/glean package in the Bergamot extension, we get the following error:

Cannot find module '@mozilla/glean/webext' or its corresponding type declarations.

I am mostly sure that the problem is with our types definitions. If you look at this thread , you'll notice that it is not ironed out exactly how exports and type declarations play together.

I have used the typesVersions workaround since the change to use exports, because I am basing myself off of how jose does thigs.

I seem to be using it incorrectly. In this branch I made some experiements. You'll see that I included conditional imports for different environment, after noticing that bergamot is expecting commonjs modules. That was not the issue, but since I've already done the work I decided to keep it (we had a bug for it anyways).

Playing around with the typesVersions field was more promising. The way that is is right now I finally don't get an error when importing Glean in in the Bergamot extension 🎉

Screenshot 2021-02-24 at 12 25 55

I also don't get an error when running yarn run build:production. Yay!

Sadly the minute I use the imported Glean object, either through Glean.initialize or even console.log(Glean) I get back to the same Cannot find module....

Also this only solves the /webext import, when attempting to do something like /webext/private/ping for example, we get back to not being able to import.

@brizental
Copy link
Contributor Author

Thought: Seems like the import cares about the path for the types definitions (notice that in the vscode screenshot I provided the module path points to its type defiitions). Maybe, it error only when I actually call Glean, but the actual code is only imported upon first call, up until then it only cares about types definitions.

I have no basis for this claim, just assumptions based on these experiences. Could be due to the usage of yarn maybe? Remember the import errors do not happen in our own sample web extension.

@brizental brizental marked this pull request as ready for review February 24, 2021 16:55
@brizental brizental changed the title Attempt to fix import errors Fix errors when importing Glean.js in Typescript environments Feb 24, 2021
Copy link
Contributor

@Dexterp37 Dexterp37 left a comment

Choose a reason for hiding this comment

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

r+wc

@brizental brizental merged commit 434322c into mozilla:main Feb 24, 2021
@brizental brizental deleted the attempt-import-fix branch February 24, 2021 17:47
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.

2 participants