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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parcel Incorrectly Detects Destructuring Assignment As Module Usage #7597

Closed
an0nusr opened this issue Jan 23, 2022 · 2 comments 路 Fixed by #7599
Closed

Parcel Incorrectly Detects Destructuring Assignment As Module Usage #7597

an0nusr opened this issue Jan 23, 2022 · 2 comments 路 Fixed by #7599

Comments

@an0nusr
Copy link

an0nusr commented Jan 23, 2022

馃悰 bug report

When using Parcel 2.2.0 with a single HTML file with an inline script, Parcel incorrectly identifies a destructuring assignment as some sort of module, triggering the error: @parcel/transformer-js: Browser scripts cannot have imports or exports. when running parcel build.

Writing this will trigger the error in an inline script block:

let [prev, last] = getLastLine(currentBlock)

However, writing this does not:

let res = getLastLine(currentBlock)
let prev = res[0]
let last = res[1]

馃帥 Configuration (.babelrc, package.json, cli command)

Package json:

{
  "name": "furryfont",
  "version": "1.0.0",
  "source": "index.html",
  "browserslist": "> 0.5%, last 2 versions, not dead",
  "author": "anonusr",
  "license": "AGPL-3.0-only",
  "scripts": {
    "start": "parcel",
    "build": "parcel build",
    "deploy": "echo 'furryfont.anonusr.org' > ./dist/CNAME && gh-pages -d dist"
  },
  "devDependencies": {
    "gh-pages": "^3.2.3",
    "parcel": "^2.2.0"
  }
}

馃 Expected Behavior

The inline script, that does not use any modules, should build as expected.

馃槸 Current Behavior

Parcel incorrectly declares that I'm using a module when I attempt to build the package:

馃毃 Build failed.

@parcel/transformer-js: Browser scripts cannot have imports or exports.

  /home/user/furryfont/index.html:81:1
    80 |
  > 81 |         <script>
  >    | ^
    82 |             function render_editor() {
    83 |                 window.quill = new Quill('#editor', {

  馃挕 Add the type="module" attribute to the <script> tag.
  馃摑 Learn more: https://parceljs.org/languages/javascript/#classic-scripts

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

馃敠 Context

This was frustrating as I needed to go through my last commit line by line to see what was causing the build system to fail. I knew I hadn't used an import, so the error caught me offguard.

馃捇 Code Sample

You can view my code here: https://github.com/an0nusr/furryfont/commits/main

The issue began when I introduced the destructuring assignment in commit 9df206bc65b559d8326f5263d66f3b4e1cbdac23.

It resolved when I rewrote the line in commit: 7e279a691c8faeeaac536debf3557b1ec838322c

馃實 Your Environment

Software Version(s)
Parcel 2.2.0
Node v12.22.7
npm/Yarn yarn 1.22.5
Operating System Ubuntu 18.04
@Shinyaigeek
Copy link
Contributor

Shinyaigeek commented Jan 23, 2022

This bug seems to be caused by this line. when swc parses code, swc replaces let [prev, last] = getLines() with

const _helpers = require("@swc/helpers");
let [prev, last] = _helpers.slicedToArray(getLastLine());

@Shinyaigeek
Copy link
Contributor

Shinyaigeek commented Jan 23, 2022

I sent PR to fix this #7599

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 a pull request may close this issue.

2 participants