parcel: Uncaught TypeError: (xxxx) is not a function

🐛 bug report

When I start the parcel dev server after a night or something, and open up my browser, randomly I get a “Uncaught TypeError: **** is not a function”. It happend with 3 different things the past days, and it’s getting annoying. Workaround rm -rf .cache dist

🎛 Configuration (.babelrc, package.json, cli command)

.babelrc

{
  "presets": ["stage-0", "env", "react"],
  "plugins": ["transform-class-properties"]
}

package.json

{
  "name": "frontend-graphql",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "apollo-cache-inmemory": "^1.2.2",
    "apollo-client": "^2.3.2",
    "apollo-link": "^1.2.2",
    "apollo-link-context": "^1.0.8",
    "apollo-link-error": "^1.1.0",
    "apollo-link-http": "^1.5.4",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "graphql": "^0.13.2",
    "graphql-tag": "^2.9.2",
    "react": "^16.4.0",
    "react-apollo": "^2.1.4",
    "react-dom": "^16.4.0",
    "react-router-dom": "^4.3.1"
  },
  "scripts": {
    "start": "parcel public/index.html"
  },
  "devDependencies": {
    "parcel-bundler": "^1.9.4"
  }
}

🤔 Expected Behavior

not error and work correctly

😯 Current Behavior

read the report ^^

image

💻 Code Sample

https://gitlab.com/homework-manager/hwm-frontend

🌍 Your Environment

Software Version(s)
Parcel 1.9.4
Node 10.5.0
npm/Yarn Yarn 1.7.0
Operating System Arch Linux // kernel 4.17.2-1-ARCH

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 11
  • Comments: 23 (4 by maintainers)

Most upvoted comments

Released in v1.9.5.

I run into the same problem:

After removing .cache I build my app and everything is working just fine. Then I touch one of the modules (product.js in that case), changing nothing in the source, and build output gives me an error.

Diff between builds shows that with cache parcel uses same ids for different modules:

without cache < },{... ,"./product":8,"./locator":9}]},{},[1], null)
---
with cache    > },{... ,"./product":9,"./locator":9}]},{},[1], null)

Building with --no-cache gives correct bundle every time.

@emilniklas in #1596 tells about the same behaviour.

parcel 1.9.4 node 8.11.2 npm 6.1.0 Ubuntu linux

@joseluisq Have you solved this problem? I’m using the same version of Parcel and React as yours, and using antd too. My errors are on the same line as yours too (h is not a function).

I believe this is related to storing asset ids in the cache. Should be fixed by https://github.com/parcel-bundler/parcel/pull/1694. Would be great if someone could help verify!

I’ve also encountered this quite often. I’m using vue, with pug and scss. Deleting the .cache directory resolves the issue.

I had some other issues (e.g. seds -i flag has a different use on macos), but here’s my final workaround:

parcel build \
    --no-minify \
    --no-source-maps \
    --no-autoinstall \
    --no-cache \
        public/index.html

terser \
    --compress \
    --mangle \
    --toplevel \
    -- dist/src.*.js > dist/app.js

cat dist/index.html

sed -E 's/<script src=\"[\.\/]?\/src\.(.+)\"><\/script>/<script src=\"app\.js\"><\/script>/g' dist/index.html | tee dist/index.html

It’s unfortunate that this is necessary though.

@kykungz basically this issue was not addressed properly and should be re-opened.

My “workaround” was just skipping the minify process using the --no-minify flag and then invoking Terser directly.

~> parcel build \
        --no-minify \
        --no-source-maps \
        --no-autoinstall \
        --no-cache \
                public/index.html

~> terser \
        --compress \
        --mangle \
        --toplevel \
        -- dist/app.*.js > dist/app.js

It seems like something weird is happening during minify process on Parcel side.

On version 1.8.1 If I’m using: parcel build --no-minify --no-source-maps --no-cache index.html

Then output is fine. But if you remove --no-minify: parcel build --no-source-maps --no-cache index.html Then I see ReferenceError: e is not defined 551a5bcc-5069-e44a-90de-563f1fa674eb:1:60755

But on 1.7.1 parcel build --no-source-maps --no-cache index.html

results in similar error: ReferenceError: t is not defined 3f5c2c76-cd87-aa43-b9df-72208890eb7b:1:60755

Had the same issue. Downgrading to 1.8.1 helps.