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

TypeError: Cannot read property '0' of undefined #306

Closed
endersaka opened this issue Nov 12, 2019 · 4 comments · Fixed by #311
Closed

TypeError: Cannot read property '0' of undefined #306

endersaka opened this issue Nov 12, 2019 · 4 comments · Fixed by #311

Comments

@endersaka
Copy link

  • Operating System: Mac OS X Sierra 10.12.6
  • Node Version: 12.13.0
  • NPM Version: 6.12.0
  • webpack Version: 4.41.2
  • eslint-loader Version: 3.0.2

Expected Behavior

To fluently build the project. This is the expected output.

$ npm run build

> apps-script-starter@3.11.1 build /Users/a_long_path_to/copy_p_style
> webpack

Hash: 3d97da38138c3ebb365b
Version: webpack 4.41.2
Time: 2254ms
Built at: 2019-11-12 6:50:54
          Asset       Size  Chunks             Chunk Names
appsscript.json   94 bytes          [emitted]  
 code-3.11.1.js   13.1 KiB    main  [emitted]  main
     index.html  101 bytes          [emitted]  
     sidebar.js   29 bytes          [emitted]  
Entrypoint main = code-3.11.1.js
[./src/index.js] 8.94 KiB {main} [built]

Actual Behavior

This project has been created based on labnol/apps-script-starter. I was just preparing it, guessing where to insert my code in the project and figuring out how is structured. So, essentially, at this point there is almost no major changes in my configuration. Except for line 19 in ".eslintrc" file (the one with the code "no-unused-vars": "off").

  "rules": {
    "prettier/prettier": "error",
    "import/prefer-default-export": "error",
    "no-unused-vars": "off"
  },

I added this line because original project configuration prevented successful build. Since my code is in development phase I don't care if there are non used variables or functions. I will clean up later.

But, after this modification I got the following building error.

Code

$ npm run build

> apps-script-starter@3.11.1 build /Users/a_long_path_to/copy_p_style
> webpack

Hash: 167d639bcef867803449
Version: webpack 4.41.2
Time: 374ms
Built at: 2019-11-12 6:48:29
          Asset       Size  Chunks             Chunk Names
appsscript.json   94 bytes          [emitted]  
 code-3.11.1.js   4.79 KiB    main  [emitted]  main
     index.html  101 bytes          [emitted]  
     sidebar.js   29 bytes          [emitted]  
Entrypoint main = code-3.11.1.js
[./src/index.js] 979 bytes {main} [built] [failed] [1 error]

ERROR in ./src/index.js
Module build failed (from ./node_modules/eslint-loader/dist/cjs.js):
TypeError: Cannot read property '0' of undefined
    at Linter.autoFix (/Users/a_long_path_to/copy_p_style/node_modules/eslint-loader/dist/Linter.js:117:20)
    at Linter.printOutput (/Users/a_long_path_to/copy_p_style/node_modules/eslint-loader/dist/Linter.js:77:12)
    at /Users/a_long_path_to/copy_p_style/node_modules/eslint-loader/dist/cacheLoader.js:46:14
    at /Users/a_long_path_to/copy_p_style/node_modules/loader-fs-cache/index.js:122:24
    at Gunzip.cb (/Users/a_long_path_to/copy_p_style/node_modules/loader-fs-cache/index.js:47:14)
    at Gunzip.zlibBufferOnEnd (zlib.js:139:10)
    at Gunzip.emit (events.js:215:7)
    at endReadableNT (_stream_readable.js:1183:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! apps-script-starter@3.11.1 build: `webpack`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the apps-script-starter@3.11.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/my_user_name/.npm/_logs/2019-11-12T05_48_29_475Z-debug.log

How Do We Reproduce?

You can simply clone my project repository https://github.com/endersaka/gas-copy-gdocs-paragraph-style, cd inside it, then run npm install followed by npm run build.

Actually I found a way to "resolve" it but I don't know if it can be considered a correct fix because I don't know the logic of eslint-loader. Though, as I said, I modified the node_modules/eslint-loader/dist/Linter.js file. At line 116, in fact, there is the definition of function autoFix(), and line 117 was the line responsible for the stacktrace error that cause the exception. I have inserted an if() just before the line causing the error to "dodge" it, as you can see in this screenshot eslint-loader possible fix.
In the development file Linter.js function autoFix() is defined at line 110.

@endersaka
Copy link
Author

Update

Since I am going on with my development I created a Git tag of the commit where I found the error.

It is eslint-loader_failure.

@mrkitan
Copy link

mrkitan commented Nov 27, 2019

@endersaka I have very similar problem in my project, but I did a temporary solutuion without edit eslint code.
In my webpack config rules of eslint-loader I disabled option "fix" and it works, but I'm waiting for final solution.

@endersaka
Copy link
Author

In my webpack config rules of eslint-loader I disabled option "fix" and it works, but I'm waiting for final solution.

Good to know @mrkitan, thanks for the suggestion.

@ricardogobbosouza
Copy link
Collaborator

Hi @endersaka
I'm releasing a fix right now

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

Successfully merging a pull request may close this issue.

3 participants