Use import and export syntax in cpanel - javascript

Currently, i'm trying to run my svelte-kit application app to cpanel, but I wasn't able to because it uses ESM, and not commonjs. I've already tried to set type to module in my package.json, to no avail. My node.js version is 14, and I've done some research and it seems to me there is no way to compile a svelte-kit application to commonjs.
I would love if someone could show me a way to compile svelte-kit applications to commonjs, or use ESM modules on cpanel.

Related

A file called pty.node.js is missing after installing "node-pty" in a electron-forge project. How can I install node-pty in Linux

After installing node-pty (an external module used to create pseudo terminals using node js) in a boilerplate electron-forge project; I found it throwing an error that some core module of node-pty is importing another module which nodejs is failing to find.
After some research I discovered that entry point of node-pty is src/index.js, which imports another module called src/unixTerminal.js (this file is imported if the system is running on linux platform and my PC is running on Ubuntu 20.04) and that module tries to import build/Releases/pty.node.js (unixTerminal.js calls many functions imported from pty.node.js, so this package cannot be ommitted) but as a matter of fact build/Releases/pty.node.js is missing and completely absent in the node_modules/node-pty folder of my project where I had installed node-pty
Why does this happen? Is this any fault of myself in installing node-pty, I had installed it directly using npm i command? If a vital file of a module is missing how can it work? Please tell me how can I use node-pty on Linux and why build/Releases/pty.node.js is missing in node-pty's directory?
Since you're using Electron Forge (a crucial detail omitted from the original post), according to this issue I found by googling "node-pty electron forge" you'll need to configure the Electron packager to unpack the pty.node file:
asar: {
unpack: '**/node_modules/node-pty/build/Release/*'
},

How to bundle npm packages for vanilla JavaScript frontend development and production builds on CDN servers?

I have a vanilla HTML/CSS/JavaScript site (repository) which uses ES6 modules. It can be successfully deployed to GitHub pages and Netlify.
In my HTML, I import main.js like this:
<script src="js/main.js" type="module" defer></script>
In my main.js file, I import other modules I have made like this:
import * as data from './data.js';
import displayUserCard from './displayUserCard.js';
Now I want to also install and import npm modules to use on my site just as I use my own code on my site.
I install lodash like this:
npm i lodash
Then in my main.js file, I import lodash like this, just as I do in my Node apps:
import _ from 'lodash';
This of course doesn't work and gives me the following error, since we are now in the browser and not in a Node app:
^Uncaught TypeError: Failed to resolve module specifier "lodash". Relative references must start with either "/", "./", or "../".^
Researching this, I understand that such a development environment needs a web bundler, but I find everything from dated tools such as Browserify and RequireJS, to over-complex tools such as WebPack, to newer bundlers such as Parcel, Vite and Snowpack which all don't seem to address this problem of easily bundling npm packages for both development and production builds.
What is the most straight-forward way in 2021/2022 to use node modules such as lodash in vanilla HTML/CSS/JavaScript frontend apps so that they can be bundled, built and deployed at CDNs like GitHub pages, Netlify and Vercel?
What you need to do is install a javascript bundler that translates and stores all the needed modules(e.g lodash) in an accessible place for your browser to find.
Watch this video, its straight to the point and sums up everything.

Error importing the Node standard library module "crypto"

When I attempt to compile my app, I get the attached error despite the fact that I am not explicitly attempting to import crypto in any of the files I have written myself. It seems that it is imported in a file automatically present in the node_modules folder. Is anyone familiar with the given error?error
The package at "node_modules\reques\lib\helpers.js" attempted to import the Node standard library module "crypto". It failed because the native React runtime does not include the Node standard library. Read more at https://docs.expo.io/introduction/faq/#can-i-use-nodejs-packages-with-expo
You can't use the request package, it included native Node.js libraries that are not supported in React Native. Use another request library that is made for React native.
This is because a dependency in your react-native project is using the crypto library.
One of the dependencies installed is not made for react-native and is made to run on the server. Find out which dependency that is and you can change it to a react-native compatible library to fix the issue.

How to setup WebStorm for Node.js project

i'm in trouble of setting Webstorm for MEAN app
To be honest, this is my first meeting with JS and I can't understand how to correctly get syntax highlight and IDE help
What should I do after these steps?:
Installed Webstorm
Installed Node.js
Installed Mongo DB
Now I’m really confused because of the need to install Node.js packages, #types, ECMA standarts, javascript libraries, babel library
Because...
IDE asks me to use export {something} but when I'm running it it doesn't work,
AND when I use module.exports = function f, other modules doesn't see my function, but it compiles!
Also, exports without module. doesn't work.
Am I really should install all of these things or there any other more simple ways?

Hot module replacement for native ES Modules (browser or Node.js) *without* Webpack? No build tools

I'm looking to add HMR to plain Node.js code or browser code written with native ES Modules.
There's no Babel, no Webpack, no transpilation, just plain JS files and ES Module import and export calls.
Can we do HMR in plain Node or browser?
Here's a pure node HMR module from a developer/entrepreneur who i work with personally: https://github.com/huan/hot-import
Hope this helps.
Snowpack is a tool which uses native ES modules to get rid of bundling and in each save changes will be reflected faster compared to setups using bundlers like Webpack.
From Snowpack website:
No More Bundling During Development: Snowpack installs your npm dependencies so that they can be imported directly in the browser without an application bundler.
Instant Dev Startup: Snowpack’s dev server starts up in less than 20ms on most machines. Files are only built on-demand, as requested by the browser.
Instant Dev Rebuilding: Never wait more than a few milliseconds when you hit save. Since there’s no large app chunks to rebuild, changes are reflected in the browser instantly.
Connect your Favorite Build Tools: Manage your build using a simple, familiar “scripts” interface that replaces traditionally complex plugin ecosystems.
Bundle for Production: It’s the best of both worlds: fast bundle-free development + optimized bundling in production. Choose between bundled (optimized) or unbundled build output without any additional config needed.
Another one is es-dev-server.
Here's a library that very much resembles the Webpack API, but for native ES Modules in the browser:
https://github.com/SevInf/heiss (also at https://www.npmjs.com/package/heiss)
And here's an article on it: https://itnext.io/hot-reloading-native-es2015-modules-dc54cd8cca01
You can also use ViteJs.
If you want use it for node server, just use the node plugin https://github.com/axe-me/vite-plugin-node with it

Categories