question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stumped on error with requiring ../encodings

See original GitHub issue

I’ve been stumped by this error a few times, and it’s really hard to reproduce because it only happens once on a new install. So in a desperate attempt to glean more information, I’m posting this here to see if someone with a bit more knowledge can help point me in the right direction.

This error seems to be something with iconv-lite failing to require ../encodings but it does exist. What’s even more strange is that if you restart the server it works fine thereafter.

Here is the stacktrace of the error:

15:40:48 err! [console] Error: Cannot find module '../encodings'
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.getCodec (/somepath/node_modules/body-parser/node_modules/iconv-lite/lib/index.js:61:27)
    at Object.getDecoder (/somepath/node_modules/body-parser/node_modules/iconv-lite/lib/index.js:118:23)
    at getDecoder (/somepath/node_modules/body-parser/node_modules/raw-body/index.js:44:18)
    at readStream (/somepath/node_modules/body-parser/node_modules/raw-body/index.js:218:15)
    at getRawBody (/somepath/node_modules/body-parser/node_modules/raw-body/index.js:106:12)
    at read (/somepath/node_modules/body-parser/lib/read.js:76:3)
    at jsonParser (/somepath/node_modules/body-parser/lib/types/json.js:121:5)
    at Layer.handle [as handle_request] (/somepath/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/somepath/node_modules/express/lib/router/index.js:312:13)
    at /somepath/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/somepath/node_modules/express/lib/router/index.js:330:12)
    at next (/somepath/node_modules/express/lib/router/index.js:271:10)
    at expressInit (/somepath/node_modules/express/lib/middleware/init.js:33:5)
    at Layer.handle [as handle_request] (/somepath/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/somepath/node_modules/express/lib/router/index.js:312:13)
    at /somepath/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/somepath/node_modules/express/lib/router/index.js:330:12)
    at next (/somepath/node_modules/express/lib/router/index.js:271:10)
    at query (/somepath/node_modules/express/lib/middleware/query.js:49:5)
    at Layer.handle [as handle_request] (/somepath/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/somepath/node_modules/express/lib/router/index.js:312:13)
    at /somepath/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/somepath/node_modules/express/lib/router/index.js:330:12)
    at next (/somepath/node_modules/express/lib/router/index.js:271:10)
    at Function.handle (/somepath/node_modules/express/lib/router/index.js:176:3)
    at EventEmitter.handle (/somepath/node_modules/express/lib/application.js:173:10)
    at Server.app (/somepath/node_modules/express/lib/express.js:38:9)
    at Server.<anonymous> (/somepath/node_modules/socket.io/node_modules/engine.io/lib/server.js:434:22)
    at Server.<anonymous> (/somepath/node_modules/socket.io/lib/index.js:260:16)
    at emitTwo (events.js:87:13)
    at Server.emit (events.js:172:7)
    at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:528:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)
  EventEmitter.logerror [console] (application.js:629)
    at Console.error (/somepath/baymax.bundle.js:160:3265)
    at EventEmitter.logerror (/somepath/node_modules/express/lib/application.js:629:43)
    at Immediate.immediate._onImmediate (timers.js:445:18)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:10
  • Comments:35 (11 by maintainers)

github_iconTop GitHub Comments

8reactions
kleggascommented, Jul 26, 2017

I got the same problem as @Marak is describing, and it does not solve if I restart. His fix worked for me. And I agree with @Marak. Instead of excusing this behaviour, treat it as the bug it is and fix, please.

6reactions
Marakcommented, Feb 9, 2017

Issue is due to changing the current working directory of node.js process after process starts and then you attempt to perform method using iconv-lite. The lazy require breaks since it’s no longer in the same relative path. Same if node_modules somehow disappears after process start.

I think I found the solution.

Try changing:

iconv.encodings = require("../encodings");

to

iconv.encodings = require("iconv-lite/encodings");

https://github.com/ashtuchkin/iconv-lite/blob/master/lib/index.js#L61

Read more comments on GitHub >

github_iconTop Results From Across the Web

express body-parser utf-8 error in test - node.js - Stack Overflow
This is because the iconv-lite module does a lazy loading of encodings . The encodings are only loaded when getCodec method gets executed....
Read more >
encodeUricomponent returns non-specific error. Stumped.
Solved: Hi, I'm trying use HTTP request POST method to send HTML code to an API. The API requires the "x-www-form-urlencoded" body type....
Read more >
Handling encoding and decoding errors in Python
This week's blog post is about handling errors when encoding and decoding data. You will learn 6 different ways to handle these errors, ......
Read more >
Syntax error in script file due to encoding? - MikroTik - Forum
I'm stumped. I have a script that I am using to configure a range of RouterOS devices from their default config out of...
Read more >
Troubleshooting Encoding Errors in Ruby - Honeybadger.io
An encoding error happens when our program can't correctly transform the string into its representation with a given encoding. I know this doesn ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found