pkg package does not include all files - javascript

I have node.js app. I installed pkg to create executable file that can be run on any platform. I use pkg . command for it. The problem is I have few csv files and config.json file where I store all of my settings. They are all in /settings/ folder. The problem is that they are not included in the pkg package and I get error after trying to run it. I tried to add
"assets": [
"settings/*",
"settings/**/*"
]
into package.json file but it didn't work. How can I add all files that are in the /settings/ folder so they are also included in the executive file without any errors?

Related

How to upload existing .tgz file into nexus3

I have already created an npm repository in Nexus3. According to my scenario, I have a build command to run then it is created as a dist folder. Under this folder, I have .tgz file. I need to upload this .tgz file to Nexus. I set up my package.json file as follows,
"publishConfig": {
"registry": "http://localhost:8081/repository/npm-private/"
},
"bin": "./dist/apps/theme-builder-app/my-theme-builder-0.0.3.tgz"
my .npmrc file is also working correctly.
Then I ran the command npm publish. After that whole project was uploaded into the nexus except my files :(
Then I configured the .npmignore as follows,
*
!./dist/apps/theme-builder-app/bst-theme-builder-0.0.3.tgz
!*/bst-theme-builder-0.0.3.tgz
That also not working.
I have attached my folder structure below, and I figured out which file I want to upload to the nexus3.

Why all files of my npm package are installed in node_modules?

Here is what I have in node_modules when I install my package:
Even though I am using this files field in package.json:
"files": [
"./dist"
]
Why is that?
Maybe you misunderstood what the files field does:
The optional files field is an array of file patterns that describes the entries to be included when your package is installed as a dependency
The files field is used to define files that should be imported alongside your library when another project install your project as a npm package.
Thats how module works.if you don't like node_modules folder try Yarn2 .
Same thing.but different module folder name.
Thats how npm works. All yours external dependencies will be downloaded to node_modules.
https://medium.com/maxkimambo/how-does-node-module-loading-actually-work-8aa63849f5ae#:~:text=Modules%20are%20the%20building%20block,are%20using%20ES6%20Javascript%20code.&text=included%20in%20your%20app.,can%20have%20their%20own%20package.

Rollup does not reslove packages from custom module folder?

I am trying to bundle an web application that written with ES6 module system & using rollup from command line with custom modules folder that I want use it as root modules directory to be resolved. Then I downloaded some packages to that custom folder with yarn add --modules-folder <custom folder path>. Now When I am using this command rollup -w -i App.js -o bundle.js -p '<modules path>/#rollup/plugin-babel={presets:["<modules path>/babel-preset-solid"]}' -p '<modules path>/#rollup/plugin-node-resolve={extensions:[".js"],customResolveOptions:{moduleDirectory:"<modules path>"}}' I am getting this error (node:13672) UnhandledPromiseRejectionWarning: Error: Cannot load plugin "<modules path>/#rollup/plugin-babel": Cannot find module '<modules path>/#rollup/plugin-babel' But I am pretty sure that all packages are in custom moduels folder path. But strangely when do same process and download packages to custom location with node_modules folder in it, It works fine. So what is the problem? What am I missing here?

How do I generate a separate package.json file in the dist directory?

I'm creating a package to publish to npm.
Can someone please help how do I generate separate package.json and
place it to dist directory? I'm using gulp as build tool.
What should be the contents of the package.json that is meant to be published? I believe we need to exclude devdependencies. I'm not sure about others.
Please help.
You should have a single package.json for your project, and it's meant to be published on NPM. The idea with devDependencies is that they won't get installed when people install your package from NPM, as opposed to dependencies, which do get installed.
For your package to work as expected, you need at least the main field that points to your main JS file.
See the docs for package.json for a list of available fields.
You should use package.json in your directory.
Publish file you want with files of package.json,
choose your main file (file will call by require) with main of package.json
You should read npm package.json
Example: (dist is directory build by gulp)
{
"name": "<your_module>",
"files": [
"dist",
"someFile.js"
],
"main": "dist/index.js",
...
}
With this way, you should add module build your module to devDependencies, module was called by your module in dependencies

.js Files Transpiled From .ts Files Don't Run In Browser

I'm trying to use the h264-converter npm package (https://www.npmjs.com/package/h264-converter).
It is written in TypeScript. When I run npm install --save h264-converter I get a folder with the .ts TypeScript files, but it also comes with the .js Javascript files in the same folder already transpiled for you.
However, the .js files it comes with do not run in a browser. They contain Require(...) functions and undefined objects like exports that cause them not to run in a browser. Simply including these .js files with <script> tags causes errors. I did some reading and tried to use the browserify npm package (https://www.npmjs.com/package/browserify) to create .js files that work in a browser from .js files that don't. I ran
browserify "C:\...\h264-converter\dist\index.js" > "C:\...\h264-converter\dist\bundle.js"
like the in the example on the browserfiy main page and it seemed to run without error (their example uses main.js instead of index.js but I think index.js serves the same purpose). It created bundle.js. However, bundle.js still doesn't run in a broswer. bundle.js still has Require(...) functions.
How do I get the .js files that come with h264-converter npm package to run in a browser?
I can post the contents of some of the .js files that the h264-converter npm package comes with if that will help. Thanks.
npm package
To use an npm (node style commonjs) package in the browser you should use a a module bundler like webpack.

Categories

Resources