Is There a way to get the full path of file dependencies in Madge API? - node.js

I'm using Magde API (https://github.com/pahen/madge/blob/master/README.md) to generate the dependency graph of my JS file...
Once the dependencies are return as object, the file paths are not clearly documented... I was wondering if there exists a way to tell Madge to specify the full path not the cut it
I want to get the dependencies of this file:
import * as t from 'C:/Users/Tec/todolist_example_jest/req2.js';
function formatName(user) {
return user.firstName + ' ' + user.lastName;
}
const element = (
<h1>
Hello, {formatName(user)}!
</h1>
);
const user = {
firstName: 'Harper',
lastName: 'Perez'
};
As we can see there exists a dependency on this file:
'C:/Users/Tec/todolist_example_jest/req2.js'; But when using madge to get the dependencies ... look below to see what is the output
Here is the code snippet:
madge('file path').then((res) => {
dependencies = res.obj(); // the dependencies as an object
console.log(dependencies);
});
and this is the output:
{
'../../../../todolist_example_jest/req2.js': [],
'simpleElement.jsx': [ '../../../../todolist_example_jest/req2.js' ]
}
../../../../todolist_example_jest/req2.js
node:fs:585
handleErrorFromBinding(ctx);
^
Error: ENOENT: no such file or directory, open '../../../../todolist_example_jest/req2.js'
at Object.openSync (node:fs:585:3)
at Object.readFileSync (node:fs:453:35)
at C:\Users\Tec\React Native Applications\Upload-main\backend\app.js:47:27
at Array.forEach (<anonymous>)
at C:\Users\Tec\React Native Applications\Upload-main\backend\app.js:44:33 {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: '../../../../todolist_example_jest/req2.js'
}

Related

Switching Storybook from Webpack to Vita in Gatsby app

I work on a Gatsby project and I'm hoping to run our Storybook with Vita instead of our existing Webpack setup. I'm clearly not doing it right.
I added the plugins:
"#storybook/builder-vite": "^0.4.2",
"#vitejs/plugin-react": "^3.1.0",
"vite": "^4.1.1",
I also added our aliases by importing my tsconfigand converting the paths to the right format.
Although most of my attempts to run it resulted in about 1000 instances of
Failed to resolve import "react/jsx-dev-runtime" from "react/jsx-dev-runtime". Does the file exist?
it's actually running now. And it booted up WAY faster than it used to.
The only issue appears to be that it's not reloading, not at all. I make a change in a component, or a change in a story, and there is zero output in the terminal running storybook.
Although I do notice that this run, although it looks like it's working in the browser, does still give only these two errors:
Failed to resolve dependency: react/jsx-runtime, present in 'optimizeDeps.include'
Failed to resolve dependency: react/jsx-dev-runtime, present in 'optimizeDeps.include'
How can I fix this? I'm so close!
I've tried...
const react = require('#vitejs/plugin-react');
//...
module.exports = {
// ...
async viteFinal(config) {
return mergeConfig(config, {
// is this where this goes?
plugins: [
react({
jsxRuntime: 'classic',
}),
],
resolve: { alias: aliasPathsVite },
},
})
},
}
Which does open Storybook in the browser, but it doesn't load, and the terminal gives endless instances of:
10:30:38 AM [vite] Internal server error: Transform failed with 2 errors:
Typography/Links.tsx:3:4: ERROR: The symbol "prevRefreshReg" has already been declared
Typography/Links.tsx:4:4: ERROR: The symbol "prevRefreshSig" has already been declared
Plugin: vite:esbuild
File: Typography/Links.tsx:1:42
The symbol "prevRefreshReg" has already been declared
1 | import RefreshRuntime from "/#react-refresh";let prevRefreshReg;let prevRefreshSig;if (import.meta.hot) { if (!window.__vite_plugin_react_preamble_installed__) { throw new Error( "#vitejs/plugin-react can't detect preamble. Something is wrong. " + "See https://github.com/vitejs/vite-plugin-react/pull/11#discussion_r430879201" ); } prevRefreshReg = window.$RefreshReg$; prevRefreshSig = window.$RefreshSig$; window.$RefreshReg$ = (type, id) => { RefreshRuntime.register(type, "Typography/Links.tsx" + " " + id) }; window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;}var _jsxFileName = "Typography/Links.tsx";
2 | import RefreshRuntime from "/#react-refresh";
3 | let prevRefreshReg;
| ^
4 | let prevRefreshSig;
5 | if (import.meta.hot) {
The symbol "prevRefreshSig" has already been declared
2 | import RefreshRuntime from "/#react-refresh";
3 | let prevRefreshReg;
4 | let prevRefreshSig;
| ^
5 | if (import.meta.hot) {
6 | if (!window.__vite_plugin_react_preamble_installed__) {
at failureErrorWithLog (node_modules/esbuild/lib/main.js:1604:15)
at node_modules/esbuild/lib/main.js:837:29
at responseCallbacks.<computed> (node_modules/esbuild/lib/main.js:701:9)
at handleIncomingPacket (node_modules/esbuild/lib/main.js:756:9)
at Socket.readFromStdout (node_modules/esbuild/lib/main.js:677:7)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
I've tried...
module.exports = {
// ...
async viteFinal(config) {
return mergeConfig(config, {
resolve: {
alias: {
...aliasPathsVite,
'react/jsx-runtime': path.join(
__dirname,
'node-modules/react/jsx-runtime'
),
},
optimizeDeps: {
include: ['react/jsx-runtime']
}
},
})
},
}
which opens a non-working Storybook in the browser, and the terminal says this hundreds of times
Failed to resolve import "react/jsx-dev-runtime" from "react/jsx-dev-runtime". Does the file exist?
Then some of these:
[vite] error while updating dependencies:
Error: ENOENT: no such file or directory, rename 'node_modules/.vite-storybook/deps_temp' -> 'node_modules/.vite-storybook/deps'
at renameSync (node:fs:1030:3)
at Object.commit (file:///node_modules/vite/dist/node/chunks/dep-3007b26d.js:42874:19)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async commitProcessing (file:///node_modules/vite/dist/node/chunks/dep-3007b26d.js:42348:17)
at async runOptimizer (file:///node_modules/vite/dist/node/chunks/dep-3007b26d.js:42386:17)
And then a bunch of issues importing CSS files, like this one
10:45:29 AM [vite] Internal server error: Failed to resolve import "./header.css" from "node_modules/#storybook/mdx1-csf/dist/esm/stories/Header.js?v=ec48b265". Does the file exist?
Have you tried something like this?
resolve: {
alias: {
'react/jsx-runtime': 'react/jsx-runtime.js',
},
},
Source: https://github.com/vitejs/vite/issues/6215
Also:
optimizeDeps.include: ['react/jsx-runtime']
Another way can be tweaking the configuration of #vitejs/plugin-react:
import react from '#vitejs/plugin-react';
export default defineConfig({
plugins: [
react({
jsxRuntime: 'classic',
}),
]
});

Using laravel browsershot

I installed Browsershot and I'm taking google's image to test it. I prepared the route but it gives an unexpected error.
Symfony\Component\Process\Exception\ProcessFailedException
The command "C:^\nodejs^\node ^"C:^\Users^\AT08877^\it-graph^\vendor^\spatie^\browsershot^\src/../bin/browser.js^" ^"^{^^"url^^":^^"http:^/^/127.0.0.1:8000^/chart^^",^^"action^^":^^"screenshot^^",^^"options^^":^{^^"type^^":^^"png^^",^^"path^^":^^"C:^^\Users^^\AT08877^^\it-graph^^\public^^\deneme.png^^",^^"args^^":^[^],^^"viewport^^":^{^^"width^^":800,^^"height^^":600^}^}^}^"" failed. Exit Code: 1(General error) Working directory: C:\Users\AT08877\it-graph\public Output: ================ Error Output: ================ [Error: ENOENT: no such file or directory, mkdtemp 'undefined\temp\puppeteer_dev_chrome_profile-XXXXXX'] { errno: -4058, code: 'ENOENT', syscall: 'mkdtemp', path: 'undefined\temp\puppeteer_dev_chrome_profile-XXXXXX' }
Route::get('/test',function ()
{
$browser = Browsershot::url('www.google.com')
->setNodeBinary("'C:\Program Files\nodejs\node'")
->setNpmBinary("'C:\Program Files\nodejs\node'")
->bodyHtml();
dd($browser);
});

child_process.spawnSync error 'ENOENT' when unzipping a file

I'm trying to execute a cli command using child_process.spawnSync to unzip a file, but when I run the code it says ENOENT even though the command works fine.
const result = spawnSync(`unzip ${path}`, [
passwordArg, // ''
outputArg, // ''
]);
// console.log(result)
error: Error: spawnSync unzip /<...>/unzipFiles/test/zipp.zip ENOENT
...
errno: -2,
code: 'ENOENT',
syscall: 'spawnSync unzip /<...>/unzipFiles/test/zipp.zip',
path: 'unzip /<...>/unzipFiles/test/zipp.zip',
spawnargs: ['', '']
If I copy and paste and execute the exact value for path, i.e. unzip /<...>/unzipFiles/test/zipp.zip, it runs as expected.
Any help would be much appreciated.

How to get PostgreSQL dump database file using Node JS

I tried to generate postgresql dump file using Node JS. SO, I used secure-backup library to generate pg-dump file encrypted. I add this package in my project and I configured .pem file also. When I execute this file it's throwing some error. but I couldn't understand what type error is throwing and how to fix it I don't know. Any one give some suggestion how to resolve this issue to generate pg dump file using Node JS otherwise different library used to generate pg dump file.
CODE
let secureBackup = require('secure-backup');
let pgHandler = require('secure-backup/lib/handlers/pg')
console.log('hi')
let backup = secureBackup({
pubKeyPath: 'C:/Users/DELL/Desktop/Twilio_Phone/cert.pem', // path to your public key
outputPath: 'C:/Users/DELL/Desktop/DB_Dump', // where to output your encrypted backup
compress: true, // enable compression (gzip)
handler: pgHandler({
user: 'postgres',
password: '*****',
database: '****'
})
})
backup() // can be invoked directly
// or used with a cron-job module like node-schedule
Error
events.js:292
throw er; // Unhandled 'error' event
^
Error: spawn pg_dump ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
at onErrorNT (internal/child_process.js:465:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
at onErrorNT (internal/child_process.js:465:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: -4058,
code: 'ENOENT',
syscall: 'spawn pg_dump',
path: 'pg_dump',
spawnargs: [ '-U', 'postgres', 'HP', 'hummapi' ]
}

Node.JS include Jade file errno: -2,

Error when i try to include file in jade
html
include head.jade
body
{
errno: -2,
code: "ENOENT",
syscall: "open",
path: "/server/layouts/head.jade"
}
path is correctly 100%, pls help me to fix this problem!
Use the ./ notation to ensure you are loading from the current path.
html
include ./head.jade
body

Resources