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.

import/require not working

See original GitHub issue

After npm install jsnet… tried:

const {
  Network,
  Layer,
  FCLayer,
  ConvLayer,
  PoolLayer,
  Filter,
  Neuron,
  NetMath,
  NetUtil
} = require('jsnet')

console.log(Layer)
import {
  Network,
  Layer,
  FCLayer,
  ConvLayer,
  PoolLayer,
  Filter,
  Neuron,
  NetMath,
  NetUtil
} from 'jsnet'

console.log(Layer)

Outputs undefined.

Any ideas?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DanRutacommented, Jan 4, 2018

I see. I’ve not heard of that before. I’ve set it up, and I do see an empty object, when require()-ing jsNet, so I can only assume there’s an incompatibility with how jsNet exports its classes, and how it gets bundled by parceljs.

One thing I can think of is that jsNet exports all its classes as, for example: typeof window=="undefined" && (exports.PoolLayer = PoolLayer)

I’m going to guess that as window is actually defined when loading it in the browser, it just never binds the classes to the export object.

And I guess the bundling must have its own scope, or something, so that the classes are not globally accessible, as they would otherwise be.

Give me a sec, if this is the case, I’ll push some changes, and maybe that will fix it.

EDIT: Yep, that was it.

0reactions
DanRutacommented, Jan 4, 2018

Ok, try installing v3.0.1. Just tried it myself and it worked.

Just a side note, if you’re planning to use the WebAssembly version, you need to be able to serve the NetWASM.wasm file, which gets requested from the root domain (like /NetWASM.wasm). You can find it in node_modules/jsnet/dist/NetWASM.wasm

Read more comments on GitHub >

github_iconTop Results From Across the Web

require() not working in module type nodejs script
If I remove the "type": "module" line from package. json, and rewrite all of my imports to requires, everything works without an error....
Read more >
How to fix the error `require is not defined` in Node.js
It means that the default way of using npm modules is not require anymore, but import . Solution. To get rid of the...
Read more >
Javascript - How to fix ReferenceError: require is not defined
The JavaScript require() function is only available by default in Node.js environment. This means the browser won't know what you mean with the ......
Read more >
How To Fix ReferenceError require is not defined in JavaScript
You are using require in a Node.​​ In this case, check your package. json file for an property called type . If that...
Read more >
JavaScript require vs import - Flexiple
To use the require() statement, a module must be saved with .js extension as opposed to .mjs when the import() statement is used....
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