VS Code - Golang "go module packages.Load error" - linux

Backstory
I got this error amongst numerous others setting up a new virtual box LMDE5 on my new windows 11 pro computer. I haven't used windows in about 12 years, and the changes were crazy causing countless errors on Windows and LMDE5 Vbox.
My last issue was this in vs code.
Error
go module packages.Load error: err: exit status 2: stderr: go: no such tool "compile": go list
My project directory structure
.
├── docker-compose.yaml
├── project.code-workspace
├── go.mod
├── go.sum
├── main.go
└── sub_packages
├── backend
│ ├── folder1
│ ├── folder2
├── api
│ ├── handlers
│ └── requests
├── entities
├── services
└── utils
settings.json file
{
// ...
"go.goroot": "/usr/local/go",
"go.gopath": "/home/user_name/go",
// ...
}

Solution
Add the go tool dir ENV variable directly to VS Code settings.json to the settings to pickup the location of the folder .../linux_amd64 where compile was located.
settings.json file
{
// ...
"go.goroot": "/usr/local/go",
"go.gopath": "/home/username/go",
"go.alternateTools": {
"GOTOOLDIR": "/usr/local/go/pkg/tool/linux_amd64"
},
// ...
}

Related

For all subfolders in a Node.js project, use global custom entry point for require

Question
Is it possible to configure a global, custom entry point to be used by require for all subfolders in a Node.js project?
Rationale
When working in Node.js, I like having my index.js file as the topmost file in each subfolder in my IDE.
However, depending on the IDE and the way it sorts files, this is not always possible (for example, VSCode has several sorting options available, and none of them can achieve this).
To achieve that, I prefix it with _index.js, but then lose the built-in capability of require to recognize it as the default entry point.
Although this can be mitigated by adding a package.json into each subfolder, with a main property directing to the entry point file - I'd like to know if there's a way to define a "global" custom entry point, be it in the topmost package.json or using some npm package which I'm not aware of.
Example
Let's say I have the following folders structure, and assume that our IDE sorts files alphabetically:
MyApp
├── app.js
├── package.json
├─┬ featureA
│ ├── func1.featureA.js
│ ├── func2.featureA.js
│ └── index.js
└─┬ featureB
├── func1.featureB.js
├── func2.featureB.js
└── index.js
To keep index.js as the topmost file, we prefix it with an underscore, and use a package.json for each subfolder to define it as an entry point:
MyApp
├── app.js
├── package.json
├─┬ featureA
│ ├── _index.js
│ ├── func1.featureA.js
│ ├── func2.featureA.js
│ └── package.json
└─┬ featureB
├── _index.js
├── func1.featureB.js
├── func2.featureB.js
└── package.json
The package.json for both featureA and featureB is identical:
{
"main": "_index.js"
}
That package.json is necessary so that we can use require in the following way in app.js:
// app.js
const featureA = require('./featureA');
const featureB = require('./featureB');
But can these two package.json files be replaced with some "global" alternative?

Typescript folder structure in a project with client, server and shared code

I have a project with the following structure
project
├── client
│ └── src
│ ├── index.js
│ ├── and.js
│ ├── some.js
│ ├── other.js
│ └── files.js
├── public
├── server
│ ├── out
│ │ ├── index.js
│ │ └── any.other.dependency.js
│ ├── src
│ │ ├── index.ts
│ │ └── foo.js
│ └── templates
├── shared
│ └── constants.js
└── mutliple.config.files.json
My goal is to have a server with all the server logic inside server/src, which serves different html files from server/templates. I want the server code to use Typescript, and the compiled output should go to server/out.
There's also the client side of the application, which lives in client/src. The logic there is complex enough that I decided to use webpack for bundling. I might even add some react in the future. All this code is compiled by webpcak and the resulting files live in /public.
I also share some constants between the client and server logic, and I decided to put them in ./shared. I might want to add some utilities there in the future, so let's assume it's not just constants.
At some point in the future I'd like to migrate the whole project to TS, but I'm not close to that yet.
How can I achieve this with Typescript?
I have the webpack side sorted out. My problem comes with the TS compiler. I can't manage to get it working because shared is out the compilerOptions.outDir, but if I set it as the whole project folder I end up with a crazy server/out folder structure. Something like server/out/server/src/index.js
My tsconfig.json looks like this:
{
"extends": "#tsconfig/node12/tsconfig.json",
"include": ["server/src/*", "shared/*"],
"exclude": ["node_modules"],
"compilerOptions": {
"allowJs": true,
"noImplicitAny": false,
"outDir": "./server/out/",
"rootDir": "./server/src"
},
}

How to Edit homepage: skeleton generated by express generator

I am new to Node.js application development with expressjs framework.
I created a skeleton with expressjs-generator.
This skeleton have following directories and files:
.
├── app.js
├── bin
│ └── www
├── package.json
├── public
│ ├── images
│ ├── javascripts
│ └── stylesheets
│ └── style.css
├── routes
│ ├── index.js
│ └── users.js
└── views
├── error.jade
├── index.jade
└── layout.jade
After it: I use the following command to run this application.
set debug=myapp:* & start npm
Now this is successfully running at Port 3000
This shows the homepage with Express Welcome message.
I want to make change in Homepage of my application. How it can be possible?
You can do that by changing the index.jade as #brute_force mentioned. If you are not familiar with jade, you can also add a index.html in the public folder and update the index.html instead.

can't copy deep folder structure with gulp

I"m getting the strangest behavior.
I have a gulp file it has three tasks. clean, copy a bunch of stuff to a folder, copy entire folder to other destination.
It seems to copy MOST of the entire folder, but leaves certain folders empty. There is no rhyme or reason, they are all folders that container javascript files and folders. Makes no sense.
Here's what I got.
gulp.task('clean', function(cb) {
del([config.get("deploy.output.deploy"), config.get("deploy.buildDirectory")],{force:true}, cb);
});
gulp.task("copy-source",["clean"], function () {
gulp.src("src/**")
.pipe(gulp.dest(config.get("deploy.output.app")+"/src"));
gulp.src(["package.json", "server.js", "bootstrap.js"])
.pipe(gulp.dest(config.get("deploy.output.app")));
gulp.src("config/**")
.pipe(gulp.dest(config.get("deploy.output.app")+"/config"));
return gulp.src("deploy/*")
.pipe(gulp.dest(config.get("deploy.output.deploy")));
});
gulp.task("copy-to-buildDir",["copy-source"], function () {
return gulp.src(config.get("deploy.output.deploy")+"/**")
.pipe(gulp.dest(config.get("deploy.buildDirectory")));
});
gulp.task("deploy",[ "copy-to-buildDir"]);
src folder structure looks like this, more or less obviously psudo structure
output
└── app
├── config
│ └── file7.js
├── src
│ ├── modules
│ │ ├── ges
│ │ │ ├── file1.js
│ │ │ └── file2.js
│ │ └── file3.js
│ ├── file4.js
│ └── controllers
│ └── file5.js
└── file6.js
dest folder structure looks like this
output
└── app
├── src
│ ├── modules
│ │ └── EMPTY
│ └── controllers
│   └── file5.js
└── file6.js
so modules and controllers are sisters, and one has the files one does not. makes no sense.
if you have any ideas I'd greatly appreciate it.
also the building up of the src (the first task) works every time. Also
I've tried just about every concievable permutation of the dependencies e.g. ["clean"]
below task definition is not correct
gulp.task("copy-source",["clean"], function () {
gulp.src("src/**")
.pipe(gulp.dest(config.get("deploy.output.app")+"/src"));
gulp.src(["package.json", "server.js", "bootstrap.js"])
.pipe(gulp.dest(config.get("deploy.output.app")));
gulp.src("config/**")
.pipe(gulp.dest(config.get("deploy.output.app")+"/config"));
return gulp.src("deploy/*")
.pipe(gulp.dest(config.get("deploy.output.deploy")));
});
you are doing 4 copies but checking the end of only final copy stream.
Either separate them into 4 tasks or combine the src and create single task to solve the issue

Ignore folders in .couchappignore

My CouchApp has the following folder structur, where files inside the app folder are compiled into the _attachments folder:
my_couchapp
├── _attachments/
│ ├── app.js
│ ├── app-tests.js
│ └── index.html
├── app/
│ └── app.js
├── Assetfile
└── views/
I want to exclude the file Assetfile, _attachments/app-tests.js and the folder app.
My current .couchappignore looks like this:
[
"app",
"Assetfile",
"_attachments/app-tests.js"
]
But this doesn't seem to work. All files beginning with app inside the _attachments folder are not pushed.
How do I define folders and specific files to be excluded when the CouchApp is pushed via couchapp push?
After a little more experimentation I found a way: the app folder can be excluded by specifying app$, so the final .couchappignore now looks like this:
[
"app$",
"Assetfile",
"app-tests.js"
]
In case you arrived here looking for a way to ignore subfolders, you are just like me. Here's my problem:
my-couchapp/
├── node_modules/
│ ├── react.js
│ ├── url/
│ ├── browserify/
│ └── coffee-script/
├── app/
│ └── app.js
└── views/
I wanted to include node_modules/react.js and node_modules/url/ (and all subfolders), but didn't want to include node_modules/browserify/ and node_modules/coffeescript.
I was trying
[
"node_modules/browserify$",
"node_modules/coffee-script$"
]
but it wasn't working.
[
"node_modules\/browserify",
"node_modules\/coffee-script"
]
also didn't work.
The only thing that worked was
[
"browserify",
"coffee-script"
]
I don't know why.

Resources