node_modules not installed when running 'vsce package' command - visual-studio-code

I wrote a VSCode extension and am trying to publish it locally via vsce package. When I install my app through the VSIX file, there's no 'node_modules' folder inside my extension which leads to my extension not loading correctly because no modules are found
I have checked that my required dependencies are indeed inside dependencies and not peerDependencies or devDependencies. I should note that I have a .vscodeingore file containing the following:
.vscode/**
.vscode-test/**
out/test/**
src/**
.gitignore
vsc-extension-quickstart.md
**/tsconfig.json
**/tslint.json
**/*.map
**/*.ts
node_modules
webpack.config.js
I would like that my node_modules be installed and I would see a "node_modules" folder inside my './vscode/extensions/' folder.
Thanks!

Related

Adding dependency removes VS code intelliSense for another local npm workspace dependency

Not sure if this is user error or a bug but I have 3 npm packages that if they exist in my package.json they remove intelliSense for all my other local npm dependencies from my npm workspaces monorepo. Importing the modules still work manually, even if intelliSense doesn't think they exist.
folder structure
/apps
/docs
package.json (does not contain yjs dependencies, intellisense works fine in this folder)
/documentation
package.json (contains yjs dependencies, intellisense to /packages modules does not work)
/packages (contains the modules that is removed)
package.json
"workspaces": [
"apps/*",
"packages/*"
],
These three packages cannot be in package.json. Removing these three dependencies will enable intelliSense to work properly.
"y-webrtc": "^10.2.0",
"y-websocket": "^1.3.16",
"yjs": "^13.5.13"

Include or Exclude node_modules with esbuild

I am using esbuild to build a vscode extension. The build gives a warning like:
✨ Done in 1.28s.
This extension consists of 7026 files, out of which 5430 are JavaScript files. For performance reasons, you should bundle your extension: https://aka.ms/vscode-bundle-extension . You should also exclude unnecessary files by adding them to your .vscodeignore: https://aka.ms/vscode-vscodeignore
DONE Packaged: /my-vscode/my-vscode-0.0.2.vsix (7026 files, 8.43MB)
I am not sure I node_modules need to be added to .vscodeignore ? when I tried doing it and installed the plugin, I get an error that my commands are not found ..
Any thoughts ?

Yarn 2 init, add failing

I'm experimenting with yarn 2 and faceplanting.
I created a new folder: /projects/yarn2/
As per their install guide https://yarnpkg.com/getting-started I ran
cd /projects/yarn2/
yarn set version berry
yarn init
then (as per their guide https://yarnpkg.com/getting-started/usage )
yarn add react
and got the following error:
Usage Error: The nearest package directory (/projects/yarn2) doesn't seem to be part of the project declared in /projects.
- If the project directory is right, it might be that you forgot to list yarn2 as a workspace.
- If it isn't, it's likely because you have a yarn.lock or package.json file there, confusing the project root detection.
$ yarn add [--json] [-E,--exact] [-T,--tilde] [-C,--caret] [-D,--dev] [-P,--peer] [-O,--optional] [--prefer-dev] [-i,--interactive] [--cached] ...
What am I doing wrong?
You either don't have package.json or yarn.lock which confuses yarn if the package is added in the workspace or not. Just run the following command and I think your problem must be solved.
cd <folder_name>/<project_name>
touch yarn.lock
yarn
Check to see if you have a package.json or yarn.lock file in your /projects directory. If you do, clear it/them out and this should start working.
To add to the previous answers what worked for me was:
It seems to be that yarn.lock file is what's really required, so if you have started with yarn v1.x and did yarn init - then you will have a package.json file in the project dir already.
If you now switch over to yarn v2 by doing yarn set berry, and want to add a package by yarn add [whatever] it will fail. You can work around that by creating an empty file by: touch yarn.lock (or on windows just cat '' > yarn.lock) after that it should work fine.
I figured out an even better / faster way to do it now, just do this in an empty project folder:
yarn init -2
this will initialize a new yarn v2 project folder with .yarnrc.yml, package.json, and the .yarn folder, also initializes an empty .git folder and adds a proper .gitignore. check by yarn --version - should echo v2.x.x
Usage Error: The nearest package directory (/<path_to_folder>/<project_name>) doesn't seem to be part of the project declared in /<path_to_folder>.
Solution:
Search for yarn.lock and package.json files inside /<path_to_folder> and delete them!
you have to remove yarn.lock and package.json file in your root directory ,some times there may be .yarnrc yarnyml files in you root directory you have to remove them also.

BabelJS: Doesn't find all .js files in directory

Babel doesn't find all of my .js/.es6 files in my directory.
I have this directory structure:
src/
assets/
sample/
models.es6
scripts/
playground.es6
If I run babel src --out-dir dist --source-maps --copy-files --presets env, it only transpiles /src/assets/sample/models.es6 and doesnt go through src/scripts/playground.es6.
What am I doing wrong?
Looking forward to your response!
You can do like below :
babel src/** --out-dir lib
more at official doc
Compile Directories
Compile the entire src directory and output it to the lib directory. You may use --out-dir or -d. This doesn’t overwrite any other files or directories in lib.
if you still stuck, you can use gulp or grunt or webpack to load/transpile mupltiple directives from different locations.
Hope it helps
I found the problem. It has barely to do with Babel.
Inside the src/assets/** is my Realm database sample.realm (https://realm.io). The file itself doesnt cause the problem. But if you open the sample.realm file with Realm Studio on MacOSX, a file called sample.realm.note gets created. This file causes babel to not exit the transpile task.

How to run babel without inflating my package?

I added babel to my project with 2 presets (es2015 and stage-0) and it added 100+ MB of dependencies to my node_modules folder.
Would it be possible to package only my transpiled code without babel dependencies, using a system-wide babel-cli? I tried installing this way but it errors:
Couldn't find preset "es2015" relative to directory "."