Ive searched this for over an hour now and no ones post helped me with my problem so i need to post i guess lol
I have some pretty simple code for a grunt task im trying to run but im getting an error.
module.exports = function(grunt){
grunt.initconfig({
pkg: grunt.file.readJSON ('package.json'),
uncss: {
dist: {
files: {
'css/style.css' : ['index.html']
}
}
}
});
grunt.loadNpmTasks('grunt-uncss');
grunt.registerTask('default',['uncss']);
};
my package file is as follows:
{
"name": "Grunt",
"version": "1.0.0",
"description": "grunt",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"tt"
],
"author": "troy",
"license": "ISC",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-uncss": "^0.4.3"
}
}
The Error im getting is:
Loading "gruntfile.js" tasks...ERROR
TypeError: undefined is not a function
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
Any assistance is greatly appreciated
Related
I am setting up the wdio using command "npm init wdio" and try to run the test files. it is giving below error
Failed launching test session: Error: Couldn't initialise "#wdio/cucumber-framework". [0-0] Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/formatter/helpers/event_data_collector' is not defined by
Below is my package.json file
"name": "wdio-new",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"wdio": "wdio run wdio.conf.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#wdio/cli": "^7.16.12",
"#wdio/cucumber-framework": "^7.16.12",
"#wdio/local-runner": "^7.16.12",
"#wdio/spec-reporter": "^7.16.11",
"chromedriver": "^96.0.0",
"wdio-chromedriver-service": "^7.2.2"
}
}
I managed to fix this issue by reinstalling node and checking the option to "Automatically install the necessary tools" during setup
I'm trying to biuld bundling through rollup.js in VSCode.
My directory:
----MyProject
--------\node_modules
-----------\.bin
-----------\rollup
--------index.js
--------index.html
--------bundle.js
--------package-lock.json
--------package.json
In my .html file I have connection with bundle.js, all changes which I'm doing in index.js must automatically be updated in bundle.js. But it's only working when I run in terminal this command: rollup index.js --file bundle.js
My package.json:
{
"name": "npm",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"rollup": "^2.34.2"
}
}
What do I need to do to make this system works automatically?
Firstly, I didn't have config file, so I've created rollup.config.js:
import serve from 'rollup-plugin-serve'
import livereload from 'rollup-plugin-livereload'
const watch = process.env.ROLLUP_WATCH
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'iife'
},
plugins: [
watch && serve('dist'),
watch && livereload()
]
}
Then I added these 2 scripts into package.json:
"build": "rollup -c",
"dev": "rollup -c -w"
And run in terminal: npm run dev
My credits to vladshcherbin for help!
I'm following the official Webpack getting started guide and I get an error on the Using a Configuration section. It says to create a webpack.config.js file with:
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist')
}
};
I then run the following command:
npx webpack --config webpack.config.js
The error I get is:
Cannot find module '/Users/Documents/Web_Development/tone/webpack.config.js'
The guide does not seem to give any ideas of what could be wrong here. Also my code editor is telling me there is an error with const path = require('path'); saying "Expected a JSON Object, array or literal;
My Directory structure:
webpack.config.json
package.json.lock
package.json
node_modules/
dist/
index.html
main.js
src/
index.js
package.json:
{
"name": "tone",
"version": "1.0.0",
"description": "",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"webpack": "^4.29.3",
"webpack-cli": "^3.2.3"
},
"dependencies": {
"lodash": "^4.17.11"
}
}
The solution was to change the webpack.config.json file to webpack.config.js.
You have to make sure that the webpack.config.js file is in the root of your project.
I am trying to implement local modules in my application
1.Project root folder i have created folder named test with a file named index.js
module.exports = {
myFunction:function(){
console.log('ok');
}
}
2.Added the following in package.json in the root folder
"dependencies": {
"test-module": "file:test"
}
3.When i try to import var module = require('test-module'); in app.js i got this error
Cannot find module 'test-module'
you can provide a path to a local directory that contains a package
{
"name": "baz",
"dependencies": {
"bar": "file:../foo/bar"
}
}
and perform npm install -s or npm install --save reference
To add on #Blaze answer, if you follow the steps (Local Paths) to install a local module, it will sort out for you the local dependency in your package.json:
npm i ./test --save
That will produce the correct local dependency entry in your dependencies in the root package.json:
"test-module": "file:test"
assuming test-module is the name in the local dep package.json.
This is how it should look like:
Make sure your test folder has a package.json.
test/package.json should have a "name" field with the value "test-module" (ie, same name as the dependency in your root package.json.
My files:
test/package.json
{
"name": "test-module",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
test/index.js
module.exports = {
t:() => console.log('t')
};
package.json
{
"name": "t",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"test-module": "file:test"
}
}
app.js
t = require('test-module');
t.t();
This is working for me.
I have as simple "hello world" project and I want to test the famous hélloWorld function.
The project is structured like this:
├── package.json
├── spec
│ ├── helloWorldSpec.js
│ └── support
│ └── jasmine.json
└── src
└── helloWorld.js
And the file content:
package.json
{
"name": "jasmineTest",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD-2-Clause",
"dependencies": {
"jasmine": "~2.1.0"
}
}
spec/helloWorldSpec.js
// var helloWorld = require('../src/helloWorld.js');
describe('Test', function() {
it('it', function() {
helloWorld();
});
});
src/helloWorld.js
function helloWorld() {
return "Hello world!";
}
// module.exports = helloWorld;
spec/support/jasmine.json
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
]
}
My problem:
When I run npm install jasmine is downloaded.
=> ok
When I run ./node_modules/jasmine/bin/jasmine.js
I have the error ReferenceError: helloWorld is not defined ReferenceError: helloWorld is not defined
My Question:
How can I access the method helloWord contained in src/helloWorld.js in the test scope without using module.exports = xxx.
A solution is to use Grunt.
Create a GruntFile.js containing:
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jasmine: {
src: ['src/**/*.js'],
options: {
specs: ['spec/**/*Spec.js'],
vendor: []
}
}
});
grunt.loadNpmTasks('grunt-contrib-jasmine');
};
Update package.json with grunt, grunt-cli and grunt-contrib-jasmine dependencies
{
"name": "jasmineTest",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD-2-Clause",
"dependencies": {
"jasmine": "~2.1.0",
"grunt": "~0.4.5",
"grunt-cli": "~0.1.13",
"grunt-contrib-jasmine": "~0.8.1"
}
}
Update npm dependencies:
npm update
And relaunch test using grunt and not directly jasmine:
./node_modules/grunt-cli/bin/grunt jasmine
And you got:
Running "jasmine:src" (jasmine) task
Testing jasmine specs via PhantomJS
Test
- it...
log: Spec 'Test it' has no expectations.
✓ it
1 spec in 0.008s.
>> 0 failures
Done, without errors.
According to Jasmine staff :
You don't need to specify your source files in the config - just require them in from your spec files.
https://github.com/jasmine/jasmine-npm/issues/49
But then, you do need to use export.
This is not a Jasmine issue but vanilla Javascript. You want to call a method from another file so you need to export and require it.
Why don't you want to ?