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

Browser scripts cannot have imports or exports. Use a <script type="module"> instead #51

Closed
prokher opened this issue Jun 27, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@prokher
Copy link

prokher commented Jun 27, 2021

Dear Maintainer(s),

I've got the following error trying to build the extension:

$ npm run build

> build
> parcel build source/manifest.json --no-content-hash --no-source-maps --dist-dir distribution --no-cache --detailed-report 0

🚨 Build failed.
@parcel/transformer-js: Browser scripts cannot have imports or exports. Use a <script type="module"> instead.
/Volumes/Dev/ProBrain/BrowserExtensionTemplate/source/options.js:4:1
  3 | 
> 4 | import optionsStorage from './options-storage.js';
>   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5 | 
  6 | optionsStorage.syncForm('#options-form');
@parcel/transformer-js: The environment was originally created here:
/Volumes/Dev/ProBrain/BrowserExtensionTemplate/source/options.html:31:1
  30 | 
> 31 | <script src="options.js"></script>
>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  32 | 

I thought I probably doing something wrong and made a GitHub clone but clicking "Use this template" button as README.md recommends, but got the same issue.

What am I doing wrong?

@fregante
Copy link
Owner

I saw this issue today too. It's possible that Parcel released another breaking change a usual.

Try adding a type="module" attribute on the script tag

@fregante fregante added the bug Something isn't working label Jun 27, 2021
@prokher
Copy link
Author

prokher commented Jun 28, 2021

@fregante, thank you, adding type="module" did the trick:

$ git diff
diff --git a/source/options.html b/source/options.html
index 40894b3..57cb974 100644
--- a/source/options.html
+++ b/source/options.html
@@ -28,4 +28,4 @@
        </div>
 </form>

-<script src="options.js"></script>
+<script type="module" src="options.js"></script>
$ npm run build

> build
> parcel build source/manifest.json --no-content-hash --no-source-maps --dist-dir distribution --no-cache --detailed-report 0

✨ Built in 2.34s

distribution/manifest.json              633 B     39ms
distribution/icon.png                 1.14 KB     60ms
distribution/background.js           30.88 KB    511ms
distribution/options.html               925 B    617ms
distribution/options.9515e12b.css       616 B    1.28s
distribution/options.81ccf7e2.js     53.22 KB    727ms

@prokher
Copy link
Author

prokher commented Jun 28, 2021

Here is a pull request #52.

@wll8
Copy link

wll8 commented Aug 31, 2021

If this is caused by an update, I did not upgrade any packages, and I still received this error, which brought a lot of unnecessary trouble to the developers and brought great uncertainty to the stability of the project!

1 similar comment
@wll8
Copy link

wll8 commented Aug 31, 2021

If this is caused by an update, I did not upgrade any packages, and I still received this error, which brought a lot of unnecessary trouble to the developers and brought great uncertainty to the stability of the project!

Repository owner locked and limited conversation to collaborators Aug 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants