Skip to content

Browserify can't handle Node 12 language features in certain situations #12134

@patrickhulce

Description

@patrickhulce

Summary

Lighthouse's keeping up with latest LTS is starting to bump into outdated browserify deps. This issue tracks solving them without the need for workarounds, but also documents how to solve them.

Workarounds

In #12129 I bumped into two scenarios where browserify fails with relatively cryptic error messages that took a fair bit of time to decipher, so capturing here in case others run into them too.

Error: Parsing file file.js: visitor[(override || node.type)] is not a function

class MyClass {
  instanceField = require('./some-dependency.js').someValue
}

Fix

Move the require outside of the instance field definition.

const someValue = require('./some-dependency.js').someValue;

class MyClass {
  instanceField = someValue;
}

TypeError: baseVisitor[type] is not a function while parsing file

const someContent = fs.readFileSync('../path/to/file.js');

class MyClass {
  instanceField = 1;
}
/** @type {string} */
// @ts-ignore
const x = 1;

class MyClass {
  instanceField = 1;
}

Fix

Revert back to older constructor assignment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions