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

Module parse failed: Unexpected token #82

Closed
ferllings opened this issue Sep 23, 2022 · 2 comments
Closed

Module parse failed: Unexpected token #82

ferllings opened this issue Sep 23, 2022 · 2 comments

Comments

@ferllings
Copy link

Hello,

I've been migrating from from webextension-polyfill-ts

With the @types/webextension-polyfill, I get this error:

in ./node_modules/webextension-polyfill/dist/browser-polyfill.js

Module parse failed: Unexpected token (25:25)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|   "use strict";
|
>   if (!globalThis.chrome?.runtime?.id) {
|     throw new Error("This script should only be loaded in a browser extension.");
|   }

 @ ./src/main.ts 6:0-44 16:23-30
 @ multi ./src/main.ts

Do I miss something?

Thanks for your help

@Lusito
Copy link
Owner

Lusito commented Sep 25, 2022

Hi @ferllings, it looks like the code is using the ES6 elvis-operator. Since you are using webpack, I'm guessing you are missing https://webpack.js.org/loaders/babel-loader/ or similar to have support for these.

Another possibility is, that babel is ignoring the node-modules folders here. See this: babel/babel-loader#171

It seems that line has been added 2 months ago here: mozilla/webextension-polyfill#377.
In any way, it's not related to the types (which is this projects only goal), so you're better off asking that question in the repo for the actual code: https://github.com/mozilla/webextension-polyfill/

@ferllings
Copy link
Author

Thanks,
after updating few modules it builds without issue.

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

2 participants