Parcel: Parcel 2: Functions not defined in script tags

Created on 3 Jan 2020  ยท  1Comment  ยท  Source: parcel-bundler/parcel

๐Ÿ› bug report

In Parcel 2, calling a function defined in a <script> tag from HTML (i.e. button onclick) leads to a reference error.

๐ŸŽ› Configuration (.babelrc, package.json, cli command)

{
  "name": "parcel2-inline-script",
  "version": "1.0.0",
  "description": "Shows off a bug with inline scripts in Parcel 2",
  "main": "dist/index.html",
  "scripts": {
    "dev": "parcel src/index.html",
    "build": "parcel src/build index.html"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/JonathanTroyer/Parcel2-inline-script.git"
  },
  "author": "Jonathan Troyer",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/JonathanTroyer/Parcel2-inline-script/issues"
  },
  "homepage": "https://github.com/JonathanTroyer/Parcel2-inline-script#readme",
  "devDependencies": {
    "parcel": "^2.0.0-alpha.3.2"
  }
}

๐Ÿค” Expected Behavior

The function should be run, same as in Parcel

๐Ÿ˜ฏ Current Behavior

I get Uncaught Reference Error: x is not defined

๐Ÿ’ Possible Solution

ยฏ\_(ใƒ„)_/ยฏ It may be related to https://github.com/parcel-bundler/parcel/issues/1618. See also https://github.com/parcel-bundler/parcel/issues/3301

๐Ÿ”ฆ Context

This is blocking me from transitioning an app from Parcel to Parcel 2, as several pages use script tags on the page.

๐Ÿ’ป Code Sample

Demo repo

๐ŸŒ Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 2.0.0-alpha.3.
| Node | 12.13.0
| npm/Yarn | npm 6.12.0
| Operating System | Windows 10 Pro 1909 build 18363.535

Bug HTML Preprocessing ๐Ÿ”Œ Parcel 2 Plugins

Most helpful comment

A workaround:

window.test = function ....

>All comments

A workaround:

window.test = function ....
Was this page helpful?
0 / 5 - 0 ratings