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

Intermittent Cannot read property 'js' of null #1227

Closed
eliandoran opened this issue Apr 21, 2018 · 6 comments
Closed

Intermittent Cannot read property 'js' of null #1227

eliandoran opened this issue Apr 21, 2018 · 6 comments

Comments

@eliandoran
Copy link

馃悰 bug report

A single JavaScript file causes intermittent parcel serve errors, which miraculously solve themselves when the same file is saved again with no modifications.

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

package.json

{
  "name": "vf.wadoinvest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "UNLICENSED",
  "devDependencies": {
    "babel-core": "^6.26.0",
    "less": "^3.0.1",
    "pug": "^2.0.3"
  },
  "dependencies": {
    "assets": "^3.0.0",
    "bootstrap": "^4.1.0",
    "jquery": "^3.3.1",
    "jquery-parallax.js": "^1.5.0",
    "popper.js": "^1.14.3"
  }
}

.babelrc

Tried without a .babelrc and with:

{
    "presets": [ "env" ]
}

CLI command

parcel serve index.pug

The behaviour is more likely to occur if the cache is deleted:
rm -r dist .cache && parcel serve index.pug

馃 Expected Behavior

Parcel should serve the website properly and without errors.

馃槸 Current Behavior

馃毃  Cannot read property 'js' of null
    at JSPackager.addAsset (/usr/lib/node_modules/parcel-bundler/src/packagers/JSPackager.js:38:41)
    at JSPackager.addAssetToBundle (/usr/lib/node_modules/parcel-bundler/src/packagers/JSPackager.js:125:16)
    at JSPackager.writeBundleLoaders (/usr/lib/node_modules/parcel-bundler/src/packagers/JSPackager.js:141:18)
    at JSPackager.end (/usr/lib/node_modules/parcel-bundler/src/packagers/JSPackager.js:198:20)
    at <anonymous>

馃拋 Possible Solution

馃敠 Context

Weirdly enough, the error is generated every time the site is fully rebuilt and every now and then when making live modifications. The behaviour is mostly unpredictable.

I have a single JavaScript file which I have attached below and it seems to be the one causing the problems.

Even more strange is the fact that if you save the script file on disk without making any modifications, it will successfully compile and the site will run.

Basically, every time I start working on the project again after I've cleaned the dist and .cache directories (for deployment), I get this and have to re-save the .js file.

馃捇 Code Sample

JavaScript file

const $ = require("jquery");
window.jQuery = $;

const parallax = require("jquery-parallax.js");
const boostrap = require("bootstrap");

import headerImg from "./assets/bg/header.jpg";

$(document).ready(() => {
    $(".parallax-window").parallax({
        imageSrc: headerImg,
        position: "bottom right"
    });
    
    $(".navbar-collapse a").click(() => {
        $(".navbar-collapse").collapse("hide");
    });        
});

$(".top-nav").ready(() => {
    var offset = $(".top-nav a[data-selected]").first().offset().left;
    
    if (offset > $(".top-nav").width() - 20)    
        $(".top-nav .inner-container").scrollLeft(offset);
});

馃實 Your Environment

Software Version(s)
Parcel 1.7.1
Node 9.11.1
npm/Yarn 5.8.0
Operating System Linux 4.16.3-1-ARCH x86_64 GNU/Linux
@eliandoran
Copy link
Author

eliandoran commented Apr 21, 2018

Please note that while similar to issue #1158, it does have some specific differences:

  1. parcel build always works, even after clearing the cache.
  2. The problem reproduces itself even when the script is referenced exactly one time. Although there are multiple other files referencing back to index.pug which might negate this.

@eliandoran
Copy link
Author

Further notes

  1. It doesn't seem to be related to the contents of the script file at all, as simply replacing script.js with: // Hello produces the same behaviour.

  2. Indeed, as @jgentes mentioned in Getting Cannot read property 'js' of null聽#1158, appending -t node to parcel serve index.pug will avoid the issue. This is not a solution unfortunately, as the script would no longer function properly (jQuery does not load as a global).

@80245089
Copy link

image

I have same error. I modify the JSPackager.js The source is
if (asset.generated == null) {
return;
}

please see the image

@DeMoorJasper
Copy link
Member

@80245089 feel free to open a pr if this fixes the issue

Sent with GitHawk

@perymimon
Copy link

perymimon commented Apr 27, 2018

I just add my two cents. that happen to me just now when i update parcel from version 1.6.2 to version 1.7.1 on the almost same project ( copy paste to different directory and install all dependency from fresh )

@mischnic
Copy link
Member

mischnic commented Jan 6, 2019

Is this still an issue? If yes, could you please provide an example pug and javascript file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants