I'm trying to get started with a simple Grunt example, but I'm running into an issue with grunt-contrib-concat.
Here's my Gruntfile.js:
$ cat Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: ';'
},
dist: {
src: ['src/**/*.js'],
dest: 'dist/<%= pkg.name %>.js'
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerTask('default', ['concat']);
and my package.json:
$ cat package.json
{
"name": "Linker",
"version": "0.0.0",
"description": "A test project that is meant to be a dependency",
"repository": {
"type": "git",
"url": "git://github.com/jonbri/Linker.git"
},
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"grunt-contrib-concat": "*"
},
"author": "",
"license": "ISC"
}
Running npm install doesn't show any obvious errors:
$ npm install
$ ls node_modules/
grunt grunt-contrib-concat
Here is what my directory structure looks like:
$ ls
Gruntfile.js node_modules package.json README.md src
$ ls src
index.js
When I run grunt concat I get this:
$ grunt concat
Loading "concat.js" tasks...ERROR
>> Error: Cannot find module 'ansi-styles'
Warning: Task "concat" not found. Use --force to continue.
Aborted due to warnings.
My setup:
Lubuntu 12.10, node: v0.10.25, npm: 1.4.21, grunt-cli: v0.1.13, grunt: v0.4.5
Am I missing something?
You should run it as: grunt without concat as the task is the default one. No arguments are needed to run it. So the command to launch becomes simply:
grunt
Use this to install grunt-contrib-concat:
npm install grunt-contrib-concat --save-dev
Package.json should have something like this:
"devDependencies": {
"grunt-contrib-concat": "^0.5.1"
},
Related
I need to include the aliases from webpack into AVA when it runs.
I used webpack's resolve.alias to access all the files under src folder:
webpack.config.js
resolve: {
alias: {
'#': path.resolve(__dirname, 'src/'),
},
},
and then that # special prefix for my own modules like this:
my-module.js
import main from '#/view/main'
This is my AVA configuration:
package.json
"scripts": {
"test-unit": "ava test/unit"
},
"ava": {
"require": ["esm"]
},
Is possible to add something to package.json like in this mocha solution?
https://stackoverflow.com/a/42989394/12361834
Thank you so much for your time and help!
If I understood you well you can do it with link-module-alias npm package.
Add this to your package.json:
"scripts": {
"postinstall": "link-module-alias",
"preinstall": "command -v link-module-alias && link-module-alias clean || true"
"test": "ava"
},
"_moduleAliases": {
"#": "src"
}
npm i && npm test
If you need further details you can download a working example here.
I am working on a tool and I have installed some modules locally through NPM, and I get errors when I try to require these modules through NodeJS. I am working in Windows 10, I have already tried setting up NODE_PATH etc.
Below is the structure of my files:
->project
---->node_modules
---->src
-------->css
-------->js
----------->index.js
---->package.json
---->index.html
I populate the index.html by using index.js etc.
Below is the code of my package.json:
{
"name": "bip39",
"version": "1.0.0",
"description": "A tool for converting BIP39 mnemonic phrases to addresses and private keys.",
"directories": {
"test": "tests"
},
"dependencies": {
"bip39": "^2.6.0",
"bigi": "^1.4.2",
"create-hmac": "^1.1.7",
"nem-sdk": "^1.6.7"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/PavlosTze/bip39.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/PavlosTze/bip39/issues"
},
"homepage": "https://github.com/PavlosTze/bip39#readme"
}
Below is my require() code:
var createHmac = require("create-hmac");
var BigInteger = require("bigi");
const bip39 = require("bip39");
const nem = require("nem-sdk").default;
I have done the following steps on NPM:
1) npm init
2) npm install bip39
3) npm install nem-sdk
4) npm install bigi
5) npm install create-hmac
All these files are inside the node_modules, but still, whenever I run the code in the browser I get an 'Error: Cannot find module "bip39"', etc. for all modules.
EDIT: On another directory that I have cloned the same tool, before I merged it with another one, I get no error and everything works correctly, including the require(). etc. Do you need any of those files as well?
Can someone help me please?
try this :
rm -rf node_modules
npm install
So when I run locally the mocha test inside my repo It works just fine but when I push a commit and it runs on travis CI I keep getting this error:
sh: 1: mocha: Permission denied
npm ERR! Test failed. See above for more details.
my .travis.yml
language: node_js
node_js:
- "6"
install:
-npm install
before_script: npm install -g mocha
before_script: chmod 0777 ./node_modules/.bin/mocha
package.json
{
"name": "skeletonapp",
"version": "0.0.0",
"description": "skeletonapp",
"main": "index.js",
"author": {
"name": "li"
},
"scripts": {
"test": "mocha"
},
"dependencies": {
"chai": "^3.5.0",
"mocha": "^3.1.2"
}
}
structure of files
https://travis-ci.org/LiamDotPro/Travis-CI-NodeJS-Skeleton---Mocha-Chai/builds/173340318
test.js
var assert = require('assert');
describe('Array', function () {
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function () {
assert.equal(-1, [1, 2, 3].indexOf(4));
});
});
});
Turn on the execute permission on node_modules/.bin: https://github.com/travis-ci/travis-ci/issues/6828#issuecomment-258581083
Or, remove node_modules from your Git repository, and let Travis install it with npm install. (See https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Travis-CI-uses-npm.)
Do not install mocha to Travis-CI manually. It's here by default.
Just remove your before_script's statements from the .travis.yml file.
Trying to get Grunt to concat my CSS files into one called production.css
Here is the output from the command prompt
C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test>grunt
C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test\Gruntfile.js:2
"name": "AjaxPmodule.exports = function(grunt) {
^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected token :
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test>grunt
C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test\Gruntfile.js:2
"name": "AjaxPmodule.exports = function(grunt) {
^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected token :
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test>
Here is my Gruntfile
{
"name": "AjaxPmodule.exports = function(grunt) {
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
dist: {
src: [
'css/*.css', // All JS in the libs folder
],
dest: 'css/production.css',
}
}
});
// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-concat');
// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', ['concat']);
};roject",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-concat": "^0.5.0"
}
}
I'm using the grunt-contrib-concat to concat my files. The version is "^0.5.0"
You have for some reason gotten some extra text into your file. It should start with module.exports and you also have something extra in the end.
I think what you did was basically to paste your grunt code into a code snippet that looks like package.json:
{
"name": "ajaxProject",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-concat": "^0.5.0"
}
}
Try this:
module.exports = function(grunt) {
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
dist: {
src: [
'css/*.css', // All JS in the libs folder
],
dest: 'css/production.css',
}
}
});
// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-concat');
// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', ['concat']);
}
I'm trying to setup Travis CI on one JavaScript project hosted on GitHub but I'm getting error like
Loading "jshint.js" tasks...ERROR
>> Error: Cannot find module 'jshint/src/cli/cli'
Those are my files:
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
myFiles: ['cyrlatconverter-v0.5.4.js']
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
};
.travis.yml
language: node_js
node_js:
- 0.10
package.json
{
"name": "node-travis",
"version": "0.1.0",
"devDependencies": {
"grunt": "0.4.1",
"grunt-cli": "0.1.9",
"grunt-contrib-jshint": "0.6.0"
},
"scripts": {
"test": "grunt --verbose"
}
}
Upgrading versions as discussed in github.com/gruntjs/grunt-contrib-jshint/issues/92 solved the problem.
Also as #Dexa pointed out, for him - removal of scripts part of the package.json worked and adding following to the Gruntfile.js :
grunt.registerTask('default', ['jshint']);
For clarification, ^ above registers default grunt task to run jshint when grunt is wrote to command line.