Exclude files from type: module without changing file extension

I had to set "type": "module" in my package.json file and I would like to exclude some files from being treated as ES module files but WITHOUT changing its extension, as I need to keep it as .js file because other server scripts, (which I cannot change) points directly to that specific filename.js file and… Read More Exclude files from type: module without changing file extension

Reactjs not recognize some of the ES6 function?

I am new in Reactjs, I tried to use ES6 code in my React js file like the following, the compiler not recognized filter and includes?? Error : Uncaught TypeError: Cannot read properties of undefined(reading ‘filter’)… const noStoreName = csvFile.filter( e => categoriesFile.includes(e)) Thanks! >Solution : It seems that it’s not from compiler cvsFile is… Read More Reactjs not recognize some of the ES6 function?

Difference between module es2015 vs es2020

What is the difference between module es2015 and es2020 option in tsconfig? In oher words, is there any difference if I use es2015 modules and configure the module option to es2015 or es2020? ts-config: { /* Specify module code generation: ‘none’, ‘commonjs’, ‘amd’, ‘system’, ‘umd’, ‘es2015’, ‘es2020’, or ‘ESNext’. */ module: ‘es2015’ } vs {… Read More Difference between module es2015 vs es2020

How to succinctly export a wrapped and named function without using two names

I have a function which transforms other functions: //library: let transform = function(OriginalComponent) { let WrappedComponent (props) => { //some transformation return <OriginalComponent {…props} /> }; //I specifically need the original component to have a NON EMPTY name here Object.defineProperty(WrappedComponent, "name", { value: OriginalComponent.name }); } I currently use this in a file like so… Read More How to succinctly export a wrapped and named function without using two names

Node.js –experimental-vm-modules command line option vs "type": "module" in package.json

I’m currently rewriting a NodeJS project from a messy combination of CommonJS and Babel-transpiled ES Modules to be completely ES Module based. In the process, I’ve become a bit confused by how Node handles these things. I’ve tried to read up on it, but I seem to be missing one final piece in my understanding.… Read More Node.js –experimental-vm-modules command line option vs "type": "module" in package.json

How do I share dynamically loaded class outside scope

According to the documentation it’s possible to do like this: let myModule; if (typeof window === "undefined") { myModule = await import("module-used-on-server"); } else { myModule = await import("module-used-in-browser"); } But trying to use this module export (myClass.js): export class MyClass { constructor(){ console.log(‘MyClass Constructed’); } } this code (window.initialize() called from a callback) gives… Read More How do I share dynamically loaded class outside scope

Import default in Vue component not definied in DevTools console

Simple data example, constants.js export default { name: "John Smith", age: 10 }; Import it on the Vue component, which renders correctly. But if I use the DevTools and type c in the console… c is undefined. import c from "../constants/constants.js"; export default { name: "HelloWorld", computed: { myName() { debugger; // In DevTools, console…… Read More Import default in Vue component not definied in DevTools console

What are differences between { default as name } and { name as default } when exporting js modules?

I was taking a look to the swiper.esm.js from Swiperjs (source copied here for reference: https://jsfiddle.net/fw4zj8qk/), and the first line is export { default as Swiper, default } from ‘./core/core.js’; while the following are of the form: export { default as Virtual } from ‘./modules/virtual/virtual.js’; and in MDN docs i can find that also something… Read More What are differences between { default as name } and { name as default } when exporting js modules?