Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

🚨 Cannot read property 'clear' of undefined #7

Closed
l-hammer opened this issue Mar 1, 2018 · 2 comments
Closed

🚨 Cannot read property 'clear' of undefined #7

l-hammer opened this issue Mar 1, 2018 · 2 comments

Comments

@l-hammer
Copy link

l-hammer commented Mar 1, 2018

<!- description ->

This error occurs when eslint is saved in error, and is always present when the eslint error is resolved,how to solve? thanks~

wechatimg81

<!- repo url ->

Show a repo url: https://github.com/l-hammer/YDTemplate

<!- environment ->

Software Version(s)
Parcel "^1.6.2"
Vue "^2.5.10"
Node "^8.8.1"
npm/Yarn "^5.6.0"
Operating System "macOS High Sierra v10.13.3"
@BoltDoggy BoltDoggy added the bug label Mar 1, 2018
@zodiacfireworks
Copy link

zodiacfireworks commented Mar 1, 2018

Same problem here ✋

The error I got was

🚨  Cannot read property 'clear' of undefined
    at Bundler.bundler.on (/path_to_my_project_folder/node_modules/parcel-plugin-eslint/index.js:22:28)
    at emitOne (events.js:116:13)
    at Bundler.emit (events.js:211:7)
    at Bundler.bundle (/path_to_my_project_folder/node_modules/parcel-bundler/src/Bundler.js:212:12)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Looking at the file /path_to_my_project_folder/node_modules/parcel-plugin-eslint/index.js, I found the following code

    bundler.on('bundled', () => {
        let cache;
        try {
            cache = jsonfile.readFileSync(constFile.cacheFile);
        } catch (e) {
            cache = {};
        }
        cache.log = cache.log || [];
        if (cache.log.length) {
            bundler.logger.clear(); // -->The error is fired here
        }
        cache.log.forEach(element => {
            bundler.logger.write(element);
        });

        jsonfile.writeFileSync(constFile.cacheFile, {});
    });

I suppose that the condition if (cache.log.length) ... is not sufficient to ensure the existence of logger in the bundler. Replacing such condition for something like if (cache.log.length && bundler.logger) ... may help.

I'm working in my first project with Parcel and Vuejs, and didn't know much about JS tooling.

Software Version(s)
Parcel "^1.6.2"
Vue "^2.5.13"
Node "^8.9.3"
Yarn "^1.3.2"
Operating System "Linux Deepin 15.5"

Update

Using if (cache.log.length && bundler.logger) ... raises another error in

        cache.log.forEach(element => {
            bundler.logger.write(element); // -->New error is fired here
        });

Adding a console.log(typeOf(bundler.logger)) shows that bundler.logger is never defined.

@mzabielski
Copy link

From what I investigated, in index.js you should replace bundler.logger with logger and add

const logger = require('parcel-bundler/src/Logger');

to the top of file, because Logger instance is no longer placed as a property of Bundler.

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

No branches or pull requests

4 participants