Weird error when attempting to use browserify and babel:
./node_modules/.bin/browserify app/index.js -o bundle.js -t [ babelify --presets [ es2015 react ] ]
gives:
SyntaxError: /.../package.json: Error while parsing JSON - Unexpected token o in JSON at position 1 while parsing file: /.../index.js
at Object.parse (native)
at ConfigChainBuilder.addConfig (/.../dash/node_modules/babelify/node_modules/babel-core/lib/transformation/file/options/build-config-chain.js:155:65)
at ConfigChainBuilder.findConfigs (/.../dash/node_modules/babelify/node_modules/babel-core/lib/transformation/file/options/build-config-chain.js:107:30)
at buildConfigChain (/.../dash/node_modules/babelify/node_modules/babel-core/lib/transformation/file/options/build-config-chain.js:66:13)
at OptionManager.init (/.../dash/node_modules/babelify/node_modules/babel-core/lib/transformation/file/options/option-manager.js:369:58)
at File.initOptions (/.../dash/node_modules/babelify/node_modules/babel-core/lib/transformation/file/index.js:223:65)
at new File
I have the proper presets installed for es2015 and react, but I have no idea why it's throwing up this error. The weird thing is, this command is working on my production server...
Any ideas?
This is the package.json parsing error, Check whether there is an package.json file at my user directory, if exist, delete it.
Related
Getting nx format:write --uncommitted failed and eslint --fix failed without output error when I try to do git commit
When I try to do git commit it is showing as below
Running tasks for staged files...
.lintstagedrc.json 1 file $schema no files [SKIPPED]
{apps, libs}/**/*. {ts, tsx, js, jsx) - 1 file * eslint-fix [KILLED]
.(ts, tsx, js, jsx, json, nd, arc) 1 file nx format:write -uncommitted [SIGSEGV] Skipped because of errors from tasks. [SKIPPED]
I
✓ Reverting to original state because of errors...
✓ Cleaning up temporary files...
*nx format:write -uncommitted failed without output (SIGSEGV).
eslint --fix failed without output
I am writing an react-electron application and I noticed that when I used electron-builder to build it the binary was stuck when calling "spawn".
With "yarn start" the application can be executed without problems. Only with electron-builder it gets stuck.
Can you help ?
Thanks,
Update
It seems that the C++ binary included as part of the program can't be executed within electron. If I give the hardcoded full path to the binary it works but if I give the path from __dirname I get an error
const GetLocalPath = () => {
const path = __dirname + "/../cpp_program/"
return {
helloWorld: path+ "helloWorld",
helloWorldRepeat: path+ "helloWorldRepeat"
}
}
export function helloWorld(){
// let dir = "/Users/Rick/projects/lala/github/tutorial/electron-tutorial-app/cpp_program";
let comm = GetLocalPath().helloWorld;
The error message
internal/child_process.js:403 Uncaught (in promise) Error: spawn ENOTDIR
at ChildProcess.spawn (internal/child_process.js:403)
at Object.spawn (child_process.js:562)
at helloWorldRepeat (/Users/ricky/proje…ar/build/Lib.js:113)
at Object.<anonymous> (/Users/ricky/proje…sar/build/Lib.js:49)
at Generator.next (<anonymous>)
at /Users/ricky/proje…asar/build/Lib.js:9
at new Promise (<anonymous>)
at __awaiter (/Users/ricky/proje…asar/build/Lib.js:5)
at Object.handleInitialize (/Users/ricky/proje…sar/build/Lib.js:35)
at TestStateMachine.transition (/Users/ricky/proje…tStateMachine.js:56)
This is pretty odd because it works just fine with "yarn start", which is "tsc && electron"
package.json is shown below
"scripts": {
"start": "tsc && electron ."
},
"build": {
"appId": "com.example.myapp",
"productName": "MyApp",
"files": [
"build/**/*",
"public/**/*",
"src/images/**/*"
]
},
Update ver 2
Per Alexander's suggestion I have included
"asar": false
inside package.json
When I excute it I get a different error
Uncaught Error: spawn /Users/Rick/projects/lala/github/tutorial/electron-tutorial-app/dist/mac/MyApp.app/Contents/Resources/app/build/../cpp_program/helloWorldRepeat ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:269)
at onErrorNT (internal/child_process.js:465)
at processTicksAndRejections (internal/process/task_queues.js:80)
errnoException # internal/errors.js:510
ChildProcess._handle.onexit # internal/child_process.js:269
onErrorNT # internal/child_process.js:465
processTicksAndRejections # internal/process/task_queues.js:80
Now the error is that there is no "helloWorldRepeat" file inside /Users/Rick/projects/lala/github/tutorial/electron-tutorial-app/dist/mac/MyApp.app/Contents/Resources/app/build/../cpp_program/.
The binary is in fact located at
/Users/Rick/projects/lala/github/tutorial/electron-tutorial-app/build/../cpp_program/helloWorldRepeat
Do I have to manually create this folder and paste the binary files ?
By default, Electron Builder compiles your application and packs all resources into one large archive file (think of it as a ZIP file) which can be read just fine because Electron brings support for this format known as "ASAR".
When running the built program, the code will be read from the archive. This means that __dirname will point to a directory inside the archive. The operating system, however, cannot read from the archive. Since you did not actually include the piece of code calling child_process.spawn (), I can only speculate on why you get ENOTDIR, which hints that a given path is not a directory when it was expected to be one, but I assume this is because you point to a path inside the ASAR file.
When relying on external binaries, it is a good idea to keep them outside the ASAR archive and programmatically find the path to them (which is quite complex) or by preventing Electron Builder from compiling your app into an ASAR file. However, you would also have to ask Electron Builder to include the executable in the built version of your app. This can be done by modifying your package.json:
{
...
"build": {
"appId": "com.example.myapp",
"productName": "MyApp",
"files": [
"build/**/*",
"public/**/*",
"src/images/**/*"
],
"extraResources": [
"cpp_program/*"
]
"asar": false
},
}
(Replace "cpp_program/*" by whatever path pattern matches your desired directory, possibly even replacing /* with /**/* if there are subdirectories.)
This way, the directory cpp_program will be copied to your app's resources directory upon build. This path, according to Electron Builder's documentation, is Contents/Resources/ on MacOS. Thus, you will have to modify your path (__dirname + "../" will not work because it will point to Contents/Resources/app, but __dirname + "../../" should; if not, experimenting will lead to the correct path)*. Remember to run Electron Builder every time your C++ executable changes, as the files in the .app folder are not linked to their counterparts outside the built app.
* You can switch between development paths (__dirname + "../") and production paths (__dirname + "../../" or whatever) by checking if __dirname.includes (".app/")
I got this weird error on creating react app using create-react-app command
as stated in documentation I uninstalled globally uninstalled create-react-app as well but nothing seem to be working. There is work around by reducing the react-script version to 4.0.1 or older but I don't want this. Aren't there legit method to solve this problem. The error is:
./src/index.js 1:123
Module parse failed: Unterminated string constant (1:123)
File was processed with these loaders:
* ./node_modules/#pmmmwh/react-refresh-webpack-plugin/loader/index.js
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
> $RefreshRuntime$ = require('E:/Study Material/myProjects'/Fullstack/e-commerce/client/node_modules/react-refresh/runtime.js');
| $RefreshSetup$(module.id);
|
It looks like there is an unfinished string in your command in the Line:
$RefreshRuntime$ = require('E:/Study Material/myProjects'/Fullstack/e-commerce/client/node_modules/react-refresh/runtime.js');
It should probably be:
$RefreshRuntime$ = require('E:/Study Material/myProjects/Fullstack/e-commerce/client/node_modules/react-refresh/runtime.js');
Remove the 'after the /myProjects
Let me know if it worked! :)
I am getting error while running stylelint command on windows enviornment:
command : "lint-styles": "stylelint ./src/views/{tokens,atoms,molecules,organisms}/**/*.scss --fix",
Getting error:
Error: No files matching the pattern "'./src/views/{tokens,atoms,molecules,organisms}/**/*.scss'" were found.
at globby.then (C:\workplace\Ulta\web-common\node_modules\stylelint\lib\standalone.js:212:12)
at process._tickCallback (internal/process/next_tick.js:68:7)
While no error on Mac. What should I change in it ?
You need quotes around your glob:
"lint-styles": "stylelint \"./src/views/{tokens,atoms,molecules,organisms}/**/*.scss\" --fix"
So issue was with the folder names, I changed tokens,atoms,molecules,organisms to Tokens,Atoms,Molecules,Organisms.
Because I have folders names starting with capitals but in command I was using first letter small. Though it was working on mac as it is.
Creating build of angularjs project inside folder dist /script I am not getting one script.js file.
I have tried grunt build --prod --force command for creating the build
Running "uglify:generated" (uglify) task
JS_Parse_Error {enter code here
message: 'Unexpected token: punc ())',
filename: '../../.tmp/concat/scripts/scripts.js',
line: 5122,
col: 59,
pos: 161138,
stack:
'Error\n at new JS_Parse_Error (D:\\...node_modules\\uglify-node_modules\\uglify-js\\lib\\parse.js:1427:20)' }
>> Uglifying source .tmp/concat/scripts/scripts.js failed.
Warning: Uglification failed.
Unexpected token: punc ()).
Line 5122 in .tmp/concat/scripts/scripts.jsenter code here
Used --force, continuing.
Warning: Cannot read property min of undefined Used --enter code hereforce, continuing.