What is this Electron Forge ERROR in Electron's template (Typescript + Webpack)? - node.js

I installed Electron's template following Electron Forge page.
npx create-electron-app my-new-app --template=typescript-webpack
After that, I run
npm run start
insides my-new-app folder and the following error message were popped up in command window
$ npm run start
> my-new-app#1.0.0 start
> electron-forge start
✔ Checking your system
✔ Locating Application
An unhandled rejection has occurred inside Forge:
Error: Expected plugin to either be a plugin instance or a { name, config } object but found #electron-forge/plugin-webpack,[object Object]
Electron Forge was terminated. Location:
{}
I Google it, but no one encoutered same error.
I could use above template without error message before a week ago. So, I copy the project that were made a week ago and run. It was success. However, I run the following command
npm audit
There are 22 vulnerabilities (3 moderate, 19 high).
Errors are
got <11.8.5
Severity: moderate
and
minimatch <3.0.5
Severity: high
It could not fix by npm audit fix and npm audit fix --force. So, I fixed this error by rewriting package.json and package-lock.json. Then I deleate node_modules folder and run npm install.
These vulnerabilities are gone, but above my problem were again after I run npm run start.
I think problem is involved in #electron-forge/plugin-webpack.
However, I dont know how to fix it.
Thanks in advance.

The plugins field, under config.forge options in package.json, were generated in the following strucure:
"plugins": [
[
"#electron-forge/plugin-webpack",
{
"mainConfig": "./webpack.main.config.js",
"renderer": {
"config": "./webpack.renderer.config.js",
"entryPoints": [
{
"html": "./src/index.html",
"js": "./src/renderer.ts",
"name": "main_window",
"preload": {
"js": "./src/preload.ts"
}
}
]
}
}
]
]
Change that structure to an object with name and config fields:
"plugins": [
{
"name": "#electron-forge/plugin-webpack",
"config": {
"mainConfig": "./webpack.main.config.js",
"renderer": {
"config": "./webpack.renderer.config.js",
"entryPoints": [
{
"html": "./src/index.html",
"js": "./src/renderer.ts",
"name": "main_window",
"preload": {
"js": "./src/preload.ts"
}
}
]
}
}
}
]

Modifying the plugin syntax will only fix the issue when you run it locally.
If you export the package using npm run make, it will only display a white blank screen.
Try the solution here if you face such an issue

This was a problem in Electron Forge beta 73 or whichever version this user was running - the bug has since been fixed

Related

Electron forge throws '.../python3.8" links out of the package' error when making with asar enabled on Mac

I am trying to distribute an electron project. So I follow the official guide and use electron-forge. Here is my config.forge:
"config": {
"forge": {
"packagerConfig": {
"asar":true,
"ignore":[
"^/[.].+$",
"^/app/src$",
"^.*/tsconfig([.].*)?[.]json",
"^/angular[.]json",
"^/frontend$",
"^/build$"
]
},
"makers": [
{
"name": "#electron-forge/maker-squirrel",
"config": {
"name": "my-app"
}
},
{
"name": "#electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "#electron-forge/maker-deb",
"config": {}
},
{
"name": "#electron-forge/maker-rpm",
"config": {}
}
]
}
}
It builds fine without asar:true. But if I add asar:true, it throws this error:
An unhandled rejection has occurred inside Forge:
Error: /var/folders/k1/12r0xrxd01n7zgfpqfxppqm80000gn/T/electron-packager/darwin-arm64/my-app-darwin-arm64/Electron.app/Contents/Resources/app/node_modules/#serialport/bindings-cpp/build/node_gyp_bins/python3: file "../../../../../../../../../../../../../Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/bin/python3.8" links out of the package
Electron Forge was terminated. Location:
{}
This appears to be caused by this node-gyp issue: https://github.com/nodejs/node-gyp/issues/2713
Node-Gyp now creates links to the detect binary versions, apparently to help it consistently use the same versions during builds. These are left after the build finishes, and they point outside the project directory (e.g. to /usr/bin/python). That makes various tools refuse to bundle your node_modules with these links present.
This is really a bug in node-gyp imo, but fixing that may take some time. You could attempt to contribute a fix for that bug in the node-gyp project yourself, or in the meantime you can work around this by deleting all node_gyp_bins folders in your node_modules before building.

Jest moduleNameMapper and NPM package exports

I am developing fullstack NPM packages with multiple entrypoints (namely client, server and sometimes tests), using the exports property of package.json.
I also use a small hack to make TS work with exports until it's officially supported (see this Stack Overflow post, this hackish solution and this ticket).
The package.json ends up looking like this:
{
"name": "#vulcanjs/graphql",
"version": "0.4.7",
"main": "./dist/index.js",
"files": [
"dist/"
],
"exports": {
".": "./dist/index.js",
"./server": "./dist/server/index.js",
"./testing": "./dist/testing.js"
},
"types": "./dist/index.d.ts",
"typesVersions": {
"*": {
"server": [
"./dist/server/index.d.ts"
],
"testing": [
"./dist/testing.d.ts"
]
}
},
"description": "Vulcan graphQL schema generator",
...
You can then import using either #vulcanjs/graphql for shared code, and #vulcanjs/graphql/server for Node.js-only code.
It works perfect in my Next.js app. However, it seems to break Jest moduleNameMapper.
First, I had this:
moduleNameMapper: {
"#vulcanjs/(.*)": [
"<rootDir>/node_modules/#vulcanjs/$1",
],
},
The error is:
Configuration error:
Could not locate module #vulcanjs/graphql/server mapped as:
[
"/code/vulcan-next/node_modules/#vulcanjs/graphql/server",
].
The problem is that it tries to find a package named #vulcanjs/graphql/server: yet "server" is not a different package, it's an entrypoint of #vulcanjs/graphql.
I've also tried this:
moduleNameMapper: {
"#vulcanjs/(.*)/(.*)": [
"<rootDir>/node_modules/#vulcanjs/$1",
],
},
With this config, #vulcanjs/graphql/server is mapped to #vulcanjs/graphql. The problem is that now, server code is not found. I've checked and the problem is that this solution totally removes the /server: so #vulcanjs/graphql/server points to the main entrypoints instead of the server entrypoint.
Finally I did try to remove the moduleNameMapper, but then #vulcanjs/graphql/server package is not found by Jest. Note that I need the mapper for a use case I did not demonstrate here, so getting rid of it is possible but not the best solution.
The bug can be reproduced by installing the framework: https://github.com/VulcanJS/vulcan-next. You can clone, yarn install, unskip the test in src/models/tests/sampleModel.server.test.ts and run yarn run test:unit sampleModel. It will show the error.
Any idea how I could fix this?

Error while loading config - You appear to be using a native ECMAScript module configuration file (Jest)

UPDATED.
This error is coming up when I am making a pull request. There is a github workflow audit that runs checks on the pull request and it loads the test file from another repository.
- name: Run Audits
run: npx jest audits/ch-2 --json --outputFile=audits/ch-2.json --noStackTrace
Test suite failed to run
/Users/frankukachukwu/StudioProjects/covid-19-estimator-tksilicon-js/babel.config.js: Error while loading config - You appear to be using a native ECMAScript module configuration file, which is only supported when running Babel asynchronously.
How do I solve this issue?
SOLVED: For anyone who encounters this problem. This has got to do with Babel settings. The use of .mjs, cjs or js extension for the babel.config.extension. In my case where I was running LTE Node 12.6.2. I needed this configuration at the root of my directory babel.config.cjs. cjs is what is applicable for Nodejs when using "type"="module". See more about it here on babel docs.
module.exports = {
presets: [
[
'#babel/preset-env',
{
targets: {
node: 'current'
}
}
]
]
};
And jest.config.cjs at the root too.
In addition to "cjs" solution, I was able to resolve this issue by converting babel.config.js to babel.config.json:
{
"presets": [
[
"#babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"#babel/preset-typescript"
]
}

(Nuxt)npm run dev have wrong,node_modules error

First of all
Please forgive me for not good English, I am using google translation.
Recently just got to work, I want to turn the code in the company into localhost, which is more convenient to develop.
I don't know what happened.
I tried removing node_modules and reinstalling.I also tried npm rebuild node-sass, I still don't know where there is a problem.
Failed to compile with 19 errors:
These relative modules were not found:
* ../../../../../../../../../assets/img/icon/clock.svg in
./node_modules/css-loader/dist/cjs.js??ref--7-oneOf-1-1!./node_modules/vue-
loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??
ref--7-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--7-oneOf-1-
3!./node_modules/vue-loader/lib??vue-loader-
options!./pages/_catName/vendorList/_location_id/index.vue?
vue&type=style&index=0&id=2e9c7704&lang=scss&scoped=true&
...
...
And so on
Error message
my package.josn(1)
my package.josn(2)
my package.josn(3)
The problem is not clear but I guess you need to install css-loader first before using style-loader. Try :
npm install --save-dev style-loader
after that use style-loader and css-loader together in your config.js file. For example:
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
};

.flat is not a function only with jest

When running my tests with jest, I had the above error;
Error: Uncaught [TypeError: array.map(...).flat is not a function]
Following the solution from that issue, https://github.com/kulshekhar/ts-jest/issues/828
I've installed core-js on dependencies and putting this in jest.config.js
setupFiles: ['core-js'],
I'd receive that another error;
Error: Uncaught [Error: Not supported]
And this is occurring only with jest, I'm using babel and webpack on my application and storybook without errors on flat.
My jest.config.js
const PATH = require('./path')
module.exports = {
setupFilesAfterEnv: ['./rtl.setup.js'],
moduleFileExtensions: ['js'],
verbose: true,
moduleNameMapper: {
'#components(.*)$': `${PATH.source}/components/$1`
},
transform: {
'^.+\\.js$': 'babel-jest'
}
}
per https://github.com/kulshekhar/ts-jest/issues/828#issuecomment-433976880
this problem can be solved by running
npm install --save-dev core-js
and adding core-js to your jest config's setupFiles
"setupFiles": ["core-js"]
I installed core-js (#3.4.1) and it worked for me.
Also had to add import 'core-js'; at the top of my test file's imports.
Edit: Using it in a create-react-app project that is not ejected, so I don't access webpack files and I don't have a custom config for jest (nor jest-ts).
This error happens if your node version is old. Try to update it to the latest version.
Searching more about core-js, since it's substituting #babel/polyfill, that config has worked to me.
[
"#babel/preset-env",
{
"targets": {
"node": 4
},
"useBuiltIns": "usage",
"corejs": 3
}
]
And core-js#3 being installed as a dependency.

Resources