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.

Module is not defined

See original GitHub issue

When i export custom module error shows in console “module is not defined”. I export module in standart way: var a = (function() { //stuff }); module.exports = a;

NW 1.2 Node v7.8.0 Ubuntu 16.04

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
VasiliyIsaichkincommented, Apr 20, 2017

example.zip You have two problems in code:

  1. You put your module exporting_module.js to html as <script src="src/js/exporting_module.js" charset="utf-8"></script>. The browser tries to load it as simple js file in browser context module, not as module and can’t set exports for undefined ‘module’. Just remove this line from html
  2. You use relative path for require, but in nwjs if you call require from browser-context module you current path is where package.json. For fix problem you need use path from package.json var exportable = require("./src/js/exporting_module.js");
0reactions
xahoncommented, Apr 20, 2017

I’ve found a solution. Require requires absolute path

Read more comments on GitHub >

github_iconTop Results From Across the Web

module.exports "Module is not defined" - Stack Overflow
Now, it all loads OK, but the third require statement throws a "module is not defined", for the main.js file in the third-party...
Read more >
module not defined as an Error in javascript - Hashnode
If not than you are not using Node.js/commonjs. The pattern you are using is not meant to be used on client side. Refer...
Read more >
module is not defined in ES module scope (with sveltekit ...
I can't figure out how to use playwright with sveltekit (no typescript). I get: ReferenceError: module is not defined in ES module scope...
Read more >
JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >
referenceerror: module is not defined in es module scope this ...
ERROR ReferenceError : module is not defined in ES module scope This file is being treated as an ES module because it has...
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