Skip to content
Advertisement

Tag: module

NodeJs heap-js module: Heap is not a constructor

I am trying to initialize a minimum heap/priority queue in my server.js using the head-js module (https://github.com/ignlg/heap-js). When I run my code, I receive the following error: TypeError: Heap is not a constructor However, according to the documentation, I am initializing the heap correctly, putting in a custom constructor as the parameter. Below is my code: Answer There’s a difference

Javascript – Where are ‘import’ and ‘export’ statements legal?

I’m studying the new import, export feature in Javascript but was wondering, where in code will these statements be syntactically legal? I understand something like the following won’t be legal: (function(){ import thing from ‘./thing.js’; })(); but does this mean import is only legal at the top of the module script? Or in the global scope? E.g., what about this:

ES6 modules in Chrome

I’m trying to use ES6 modules in Chrome. From all the examples I’ve looked at the following seems to be the right way to do it, but when I run it in Chrome’s developer tools I get this error message… uncaught SyntaxError: Unexpected token { …highlighting the import statement in the module (script1.js, below) that’s trying to import the module.

require.cache equivalent in ES modules

ES Modules docs states: require.cache is not used by import. It has a separate cache. So where’s this separate cache? Is it accessible after all? I’m looking for invalidating module caching as it can be done in CommonJS modules (node.js require() cache – possible to invalidate?) Answer I saw your thread on the nodeJS github and your answer is there:

Export default was not found

I have a Vue 2 project, and I’ve written a simple function for translating months in dates, which I would like to import in one of my components, but I’m getting an error: export ‘default’ (imported as ‘translateDate’) was not found in ‘@/utils/date-translation’ The relative file path from the src folder is correct, and I am exporting the function like

Avoiding circular dependencies with Node require()?

I’m having a problem where I have an Electron app, we’ll say contained in files index.html and app.js. app.js is included in index.html with a script tag. Within app.js, I use var ENGINE = require(“./myGameEngine/”); which then requires different classes, each in their own file. It looks something like this: Unfortunately, sometimes ClassA, needs to use new myEngine.ClassB(). For example,

How can I conditionally import an ES6 module?

I need to do something like: The above code does not compile; it throws SyntaxError: … ‘import’ and ‘export’ may only appear at the top level. I tried using System.import as shown here, but I don’t know where System comes from. Is it an ES6 proposal that didn’t end up being accepted? The link to “programmatic API” from that article

es2015 modules – how to name exports dynamically

I would like to create a module, h, which exports one function for every HTML element. Here’s how it might be used: Here’s how that module is defined: I don’t like that every export has to be listed explictly. How do I make these dynamic? Answer how to name exports dynamically You can’t. import and export statements are specifically designed

Advertisement