node-prune crash build in Docker - javascript

I've use node-prune in my dockerfile configuration to remove all unnecessary files after yarn install and to reduce image size like below:
FROM node:16-alpine3.15
RUN apk add curl
RUN curl -sf https://gobinaries.com/tj/node-prune | sh
COPY package*.json ./
RUN yarn install --production=true
RUN yarn global add typescript
RUN node-prune
COPY . .
RUN tsc -p tsconfig.build.json
but during builing, tsc throw me this stack:
> [server-builder 10/10] RUN tsc -p tsconfig.build.json:
#26 5.940 error TS2688: Cannot find type definition file for 'body-parser'.
#26 5.940 The file is in the program because:
#26 5.940 Entry point for implicit type library 'body-parser'
#26 5.942 error TS2688: Cannot find type definition file for 'component-emitter'.
#26 5.942 The file is in the program because:
#26 5.942 Entry point for implicit type library 'component-emitter'
#26 5.942 error TS2688: Cannot find type definition file for 'compression'.
#26 5.942 The file is in the program because:
... and many more
but when I remove RUN node-prune from my Dockerfile then everything is ok and image is successfully builded.
Can someone tell me why node-prune crash my build and how to resolve this issue? Thanks for any help!

Related

How to solve this - Could not resolve "app/javascript/*.*" issue in Rails

I am currently working on a full-stack application where I need to use React for the Front-end and Rails for Back-end. I am using Esbuild which gives me access to make use of jsx in rails. However, I am having a series of issues with it as shown below. Please, how do I resolve this [ERROR] Could not resolve "app/javascript/*.*"
Could it be that it's not compatible with my system because I am seeing so many incompatibility issues in the log.
Done in 65.24s.
Add build script
run npm set-script build "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=assets" from "."
npm WARN set-script set-script is deprecated, use `npm pkg set scripts.scriptname="cmd" instead.
run yarn build from "."
yarn run v1.22.15
warning ..\package.json: No license field
$ esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=assets
X [ERROR] Could not resolve "app/javascript/*.*"
It looks like you are trying to use glob syntax (i.e. "*") with esbuild. This syntax is
typically handled by your shell, and isn't handled by esbuild itself. You must expand glob
syntax first before passing your paths to esbuild.
1 error
node:child_process:879
throw err;
^
Error: Command failed: C:\Users\Dennis\hello-rails-react\node_modules\esbuild-windows-64\esbuild.exe app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=assets
I had the same error while building my rails application.
In the package.json file. In the scripts section, Instead of a general path
app/javascript/*.*
I specified the exact file name
app/javascript/application.js
and my problem was solved.

How to start a TypeScript project with a JS library (without type declarations) using nodemon tool?

I would like to use a JavaScript library (without type declarations) in a TypeScript project.
I created a declaration file for the library. A declaration, for example, is declare module 'ocsp';.
It's OK when I run the project with a command "npm run build".
But, there is a problem to start a project by nodemon "nodemon src/index.ts".
It shows the following error:
error TS7016: Could not find a declaration file for module 'ocsp'. 'D:/Development/Workspace/test-project/node_modules/ocsp/lib/ocsp.js' implicitly has an 'any' type.
Try npm i --save-dev #types/ocsp if it exists or add a new declaration (.d.ts) file containing declare module 'ocsp';
How to start a TypeScript project with a JavaScript library (without type declarations) using nodemon tool?

NPM install use built package for ARM processor (Sentry)

I'm on a Raspberry pi 4. In my package.json I have:
"#sentry/browser": "^5.19.2",
"#sentry/node": "^5.19.2",
When I attempt to execute npm i with an ARM processor it won't build. It gives the error
Error: Command failed: /var/www/website/node_modules/#sentry/cli/sentry-cli --version
/var/www/website/node_modules/#sentry/cli/sentry-cli: 1: ELF: not found
/var/www/website/node_modules/#sentry/cli/sentry-cli: 2: Syntax error: ")" unexpected
This is due to the fact that sentry-cli does not have an ARM build. Here is a GitHub issue on that fact and the way you can build sentry-cli on your own. So I have built it and have the binary in my user folder. But I have no idea how to get it to look for that binary when run npm i
I tried to provide the path to my binary folder in the dependencies array, but that doesn't work since it's not a package and doesn't have its own package.json file. Any idea on how to install Sentry on an ARM?

UglifyJS could not be run in intellij when configuring as a file watcher

I'm trying to configure UglifyJS file watcher in IntelliJ as stated in this link:
minifying-javacripts
But when I try to modify a javascript file and save it, I get this error:
CreateProcess error=193, %1 is not a valid Win32 application
I've installed uglify-js with the command below:
npm install uglify-js -g
And I can minify 'js' files both from windows command line and IntelliJ's internal terminal windows. But can not configure it as a file watcher properly.
I noticed that 'uglifyjs' file in the 'bin' directory of the 'uglify-js' node module, has no suffix. Then i tried to add a '.bat' suffix to it myself hoping the file watcher could run it, but it didn't work.
try to find cmd version of uglifyjs command in this folder:
node_modules.bin\uglifyjs.cmd
and set in File Watcher/Watcher Settings/Programs
Note that install the package global may not work because Intellij may not have authorization to access User/AppData/

Can't find Typescript compiler: Command "tsc" is not valid

Just installed Typescript extension to VS2012 and followed Install TypeScript for Visual Studio 2012 and then the tutorial to call the compiler:
> tsc greeter.ts
But when i try to compile .ts file where should i type: tsc greeter.ts? Tried it in VS command line and in windows console, always get the message that tsc is not recognized as command(Command "tsc" is not valid.).
If you're using tsc as a node module, make sure you've installed it with
npm install -g typescript
Then it should be available globally in your node command prompt
Ensure you have,
C:\Program Files (x86)\Microsoft SDKs\TypeScript\0.8.0.0
or,
C:\Program Files\Microsoft SDKs\TypeScript\0.8.0.0
on your path. If not, try restarting CMD.EXE and see if shows up with a fresh copy. If that fails, try adding one of the above manually to your path.
For folks on Windows with Visual Studio Code, who don't want to install full Visual Studio just for tsc.exe, I can suggest to simply download it from here: https://www.microsoft.com/en-us/download/details.aspx?id=48593.
This is a shame that this link is missing from the TypeScript download page.
Although the installer is called TypeScript for Visual Studio 2015, it works with Visual Studio Code as well.
After you downloaded and installed TypeScript, you should manually add its installation directory (C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.0\ in my case) to the %PATH% environment variable.
Open environment variables editor:
Win + S; e, n, v, i, r, o; click Edit environment variables for your account.
In the window opened find Path user variable (note that it is not named %PATH% here, but still this is it). You probably have some path set there already. You just have to type ;, append the TypeScript install location and add one more ; in the end.
Screenshot for your reference:
After this is done, open Command Prompt and type in tsc -v. If tsc.exe's version is getting displayed, you're done. For this to work, restart Command Prompt and VS Code after making the change to the %PATH%.
P.S. If you get "error TS5057: Cannot find a tsconfig.json file at the specified directory: '.'", just create tsconfig.json file in the document root (that's probably where your .ts files are) with simple contents: {}. This means "an empty JSON file <...>. This will be sufficient for most people." (source).
Usually closing and reopen the command prompt solves the issues.
Check both of these folders to find out what TypeScript version you have:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\
C:\Program Files\Microsoft SDKs\TypeScript\
Right-click the folder showing the version number then 'copy as path'.
Paste this into your system path (quick access - Windows key then type 'env'). Then open a new command prompt console as administrator and 'tsc' should work.
If you have installed typescript for a specific folder/project i.e. not globally,then you can should use tsc command with npx
e.g
npx tsc myfile.ts
npx is used to excute a package .
As new path variable, don't use the displayed tsc version number but the TypeScript Folder Name which is different.
Sample :
tsc -v display 2.4.1
but TypeScript directory is
C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.4
Just delete AppData\Roaming\npm\tsc.ps1 file and the issue will be fixed.
In my case, I did install typescript globally by using -g flag but tsc was not recognized.
It turns out that below directory was not included in path environment variable:
C:\Users\Jitendra\AppData\Roaming\npm
Adding this directory to path variable worked for me.
In CMD type where tsc if it doesn't show a path like this C:\Program Files (x86)\Microsoft SDKs\TypeScript\typescript version you installed\ it means your tsc is not running from here.You need to change the environment path manually by following #TranslucentCloud 's answer .
You should add the following path
C:\Users\<user>\AppData\Roaming\npm
to the PATH variable. Notice that you should change the to your windows user.
This will work like a charm. Cheers!!
Try
npx tsc greeter.ts
I was getting the same error until i tried this.

Categories

Resources