import/require not working
See original GitHub issueAfter 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:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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 innode_modules/jsnet/dist/NetWASM.wasm