VSCode Extension Build Errors

So I have this crazy idea of either assisting or creating my own VSCode extension for doing some Commodore 64 Assembly coding, using the awesome Cross Assembler called Kick Assembler, or KickAss for short.

Following the "Hello World" Tutorial from the VSCode Extension page, I ran into some very weird errors.

After completing the 'yo code' builder to create my Extension, I was greeted with this "wonderful" message.

I'm all done. Running npm install for you to install the required dependencies. If this fails, try running the command yourself.


npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\paul\package.json'
npm WARN paul No description
npm WARN paul No repository field.
npm WARN paul No README data
npm WARN paul No license field.

Your extension ext5 has been created!

Now, on the surface, it would appear that everything is great and wonderful, and that there were just a couple of warning. Not having much experience with VSCode extensions, or Node.js for that matter, I just ignored the messages.

After opening the Extension in code, I tried running it by going into Debug mode by pressing the F5 key. Again, no errors, and VSCode opened with no errors.

Per the instructions, I pressed Ctrl+P and tried to run the Hello World task. Sure enough it showed on the list of tasks. I pressed enter to run it.

activating extension 'foo' failed. Cannot find modules 'c:/blah/blah/foo/out/extension'

command extension.sayHello not found

What? Looking at the error, it is telling me that the compiled extension script was not found. How can that be, there were no errors during the build?

To troubleshoot this problem, I needed to show the output of the builder, to do this, I changed the 'args' option from 'silent' to 'always', then I ran the build task. I saw this in the output.

npm WARN invalid config loglevel="always"
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Development\\Libs\\nodejs\\node.exe" "C:\\Development\\Libs\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "compile" "--loglevel" "always"
npm ERR! node v6.10.0
npm ERR! npm  v3.10.10
npm ERR! path C:\Users\paul\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\paul\package.json'
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\paul\package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\paul\npm-debug.log

Well this was interesting, there was that NOENT message again, and now this was an actual error, not a warning. The other interesting thing I noticed was that, instead of trying to use the package.json in the project, it was trying to use the package.json in my home folder.

As a test, I copied the package.json from the project, into my home folder. I knew it would not work, but I just wanted to see what happened. Sure enough, when trying to rebuild, it was worse.

npm WARN invalid config loglevel="always"
> ext5@0.0.1 compile C:\Users\paul
> tsc -watch -p ./
'tsc' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Development\\Libs\\nodejs\\node.exe" "C:\\Development\\Libs\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "compile" "--loglevel" "always"
npm ERR! node v6.10.0
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! ext5@0.0.1 compile: `tsc -watch -p ./`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ext5@0.0.1 compile script 'tsc -watch -p ./'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ext5 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     tsc -watch -p ./
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs ext5
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls ext5
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\paul\npm-debug.log

So even though I knew that was a wasted effort, it did at least prove that it was not some kind of bug in VSCode, it was indeed looking in the folder to run it, however it could not find the source files to build anything.

So it seemed like tsc was not installed. Indeed, trying to execute it resulted in errors.

> tsc -v
>
> 'tsc' is not recognized as an internal or external command

It was becoming apparent that the commands in the scripts sections of the package.json were not working properly.

I run a custom script in windows everytime a command window opens up, called my autorun.cmd, you can learn how to set that up in another post of min here.

I was looking in this script for any sines of bad paths, or somthing that might interfere with a spawned command line. And there it was.

cd %HOME%

This entry at the end of my script was put in to ensure that I was always dropped into my home folder. That explained it, that was why the build was always trying to find the package.json in my home folder. Everytime npm spawned a command line to run something it would always default to this folder.

It was simply a matter of removing this line, and everything started to look.

The moral of the story is to always check for things that are running or executing outside of the tool that is being used. I don't think that any of the error messages I received were at all helpful, and it was basically blind luck that I was able to notice that I was changing my starting directory. VSCode was assuming that everytime a cmd was executed that there were no autorun commands attached to it. Instead, they should make sure that it is spawned in the folder that it is running in.

Comments

Comments powered by Disqus