Travis CI: file from node module not found - node.js

I just configured Travis CI to also run my test cases. This is my .travis.yml file:
language: node_js
node_js:
- "0.10"
before_install: npm install -g grunt-cli
install: npm install
When it tries to run my test cases, it gives me the following error:
Error loading resource file:///home/travis/build/repo/test/node_modules/mocha/mocha.css (203).
Details: Error opening /home/travis/build/repo/test/node_modules/mocha/mocha.css: No such file or directory
Error loading resource file:///home/travis/build/repo/test/node_modules/mocha/mocha.js (203).
Details: Error opening /home/travis/build/repo/test/node_modules/mocha/mocha.js: No such file or directory
TypeError: 'undefined' is not a function (evaluating 'mocha.setup('bdd')')
So it can not find the mocha.css and mocha.js file in the node_modules folder.
I'm guessing it can not find these files because they are not uploaded to Git. This is because I specified node_modules in my .gitignore file, because I do not want to upload all the modules.
What is the common way/a clean way to fix this problem?

The simplest way to get out of this situation is
$ git add --force node_modules/mocha.css node_modules/mocha.js
$ git commit -m "Add the missing files"
$ git push
The "--force" option allows you to add files which are being ignored via .gitignore

Related

AWS CodeBuild not generating correct artifact files

I have a monorepo with yarn workspaces and have the following structure
packages
server
... #my-repo/server files
shared
translations
... #my-repo/translations files
validations
... #my-repo/validations files
and I use #my-repo/translations and #my-repo/validations are dependencies of in #my-repo/server.
To build the server app, I use the following buildspec.yml
version: 0.2
phases:
install:
runtime-versions:
nodejs: 14
commands:
- echo Installing Yarn...
- npm install -g yarn
pre_build:
commands:
- echo Installing source NPM dependencies...
- yarn install
- echo Building Shared Packages ...
- yarn buildShared
- echo Listing directories ...
- ls node_modules/#my-repo/*
- echo Installing source NPM dependencies...
- yarn install
build:
commands:
- echo Build started on `date`
- yarn workspace #my-repo/server build
post_build:
commands:
- echo Build completed on `date`
artifacts:
files:
- '**/*'
discard-paths: no
The yarn buildShared command is a command I created to build all packages that are in the shared folder (simply run yarn workspace #my-repo/foo build for all shared packages in one command)
And one of the steps is to print what is inside node_modules/#my-repo directory and this prints everything as expected (I'm expecting all of my packages to be inside and correctly build, generating a dist folder).
And this CodeBuild create a Build Artifact in S3, but when I download and open the latest created BuildArtifact, I don't see any folder node_modules/#my-repo but I see a node_modules folder with the "normal" (not from yarn workspace) packages.
After try everything I could, I decided to create a temporary directory with every package I need from #my-repo in a temporary folder that I would copy from that and put back in node_modules (I know this is wrong, but I only did this to debug what was happening).
So I added this to my buildspec.yml
- cp -r node_modules/#happyr-health/ ./temp_modules
- ls
And apparently It worked, because the ls listed the temp_modules folder, but again, when downloading the latest build from S3, there was no temp_modules.
I can't figure out why some files are generated in the artifact and others aren't.
This is the second full day I'm trying to figure out "Why aren't the files from node_modules are correctly generated in the S3 bucket?"

Which script am I missing when trying to install framework7 custom build?

npm ERR! missing script: build-core:prod
I'm receiving the above error when trying to run the custom build for framework7 - https://framework7.io/docs/custom-build.html
I have gone through each step however I am running into this problem in cmder and I'm unsure why.
The error occurs at step 7 if this info is of any value
Any help would be appreicated.
The error says it cannot find the script build-core:prod.
I could replicate this error (missing build-core:prod), by NOT INSTALLING THE DEPENDENCIES after cloning from github.
So the steps are:
1. Clone the Framework7 Github repository
git clone https://github.com/framework7io/framework7 my-app
this will download the repository in a folder called my-app
2. Install Node.js
that's another topic, hope you have that installed
3. Install Gulp
npm install --global gulp
if you don't have that
4. Install dependencies
cd my-app
npm install
be sure that you are in the root of my-app (the directory you just created for the cloned repository)
this installs all the dependencies that Framework7 Custom Build needs
5. Duplicate my-app/scripts/build-config.js
and rename the duplicate to my-app/scripts/my-config.js
6. Open my-config.js and edit it as you need
7. Go to my-app folder (the root)
and run
npm run build-core:prod -- --config scripts/my-config.js --output path/to/output/folder
path/to/output/folder is a path to the folder where you want the customised files to be, it can be (for example) f7-my-custom-build
8. The custom build is ready,
hopefully you can work with it now. :)

How to set up Travis CI to use linked (local) packages?

I use npm link myDependency within myPackage so that I can work on both at the same time (vs. publishing myDependency after every change and then updating myPackage to test it.)
I would like to be able to use Travis CI with myPackage but, as one could expect (I actually forgot, but it became quite obvious after attempting to build): running npm install on Travis won't manage to install the linked package.
So, what can I do? I saw someone suggest using a Docker container but that feels like a lot of infrastructure and I'm not experienced with Docker. Another option I thought of was adding a pre-install script to clone the dev branch of myDependency repo into the node_modules folder.
First though, I'm sure I'm not the first person who ever worked on two packages alongside each other, so there must be some consensus on how this should be done.
I solved this by replicating my development set-up on Travis.
The key to solving this involves giving Travis a way to access GitHub. To do this, log in to GitHub and go to the Personal access tokens page.
You’ll see a form with a field for the name of your token and what permissions you want to grant access to. Fill in a name such as "Travis CI Pull Repo" and select the "repo" section. None of the others are necessary, so no need to give access to them. At the bottom of the page is a green button "Generate token."
Back in your code editor, create a .travis.yml file in the root directory of your project if you don’t have one already. We will be using a RubyGem for the next step, so if you don’t have Ruby gems installed, you’ll need to download it. You can check if you have it installed by running gem -v in the terminal.
If you do, run the following in the terminal to install the Travis RubyGem:
gem install travis
Next, in the terminal, make sure you’re working in your project’s root directory, and use the Travis gem to add the access token to your .travis.yml file:
travis encrypt GH_TOKEN="token-from-github-goes-here" --add
If you were successful, your .travis.yml file should have a bunch of random text an encrypted token saved:
env:
global:
secure: "lots-of-seemingly-random-characters"
That’s it! Travis should now be able to pull (and push if that’s what you’re into) to your GitHub repository.
Obviously your .travis.yml file can vary greatly from mine, but at it’s most basic, I set up .travis.yml like this:
language: node_js
node_js:
- '6'
cache:
directories:
- node_modules
install:
- npm install
script:
- npm run lint
- npm run test
env:
global:
secure: "lots-of-seemingly-random-characters"
To add the cloning and linking of the dependency, add a before_install section with the following commands:
before_install:
- git config credential.helper "store --file=.git/credentials"
- echo "https://${GH_TOKEN}:#github.com" > .git/credentials
- cd ..
- git clone https://github.com/my-name/my-dependency.git my-dependency
- cd my-dependency
- npm install
- npm link
- cd ../my-main-project
What is this actually doing?
We configure Git to use our saved access token.
We go one directory up and clone the repository into a new folder with the same name as the repository.
We go into the repository and install its dependencies.
We create a global NPM link.
Finally, we return to the main project (the one we are running Travis on). Note that this name must match the repository’s name on GitHub as that’s the name Travis will use.
In addition, we’ll need to actually use the link created above, so in the install section add the following line:
install:
- npm install
- npm link my-dependency
Make sure you put npm link after npm install as by default npm install will obliterate any links (a very annoying bug for those of us who use npm link).

NPM Install ENOENT no such file or directory

I'm getting this error when running npm install --save-dev gulp-coffee
ENOENT: No such file or directory
I have a package.json file in my root directory though
Didn't have any issues yesterday installing node modules but today I can't install dependencies
nothing seemed to work from other similar problems on stackoverflow, I ended up just deleting my repo. Then:
git clone [my github url repo]
cd [folder with node dependencies]
npm install (installs node packages based on root package.json file)
Run my gulp commands to test gulp watch, modified files being watched to see if gulp was working as intended. check to see files being changed as intended via git diff
Worked fine for me, it doesn't solve the original problem. Not sure why my package.json files were missing or why I could not repopulate them with a npm init

write module: npm install missing dist css files

I'm writting a small module
now install it somewhere
cd /tmp
npm install git://xxxx/GongT/mymdl.git
install complete successfull
but file "global.css" gone from node_modules/mymdl/dist/ folder.
I'm sure that file node_modules/mymdl/dist/global.css is in my git repo
whats happend here?

Resources