my webpack doesn't generate file though no errors shown. PLS help :D
i'm new to all this so dont be harsh pls :D
code in webpack.config.js
module.exports = {
entry : ['./app/index.js'],
output : {
path : '/build',
filename: 'bundle.js'
}
}
using npm run build, no errors returned.
package.json
{
"name": "es6",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"build": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"webpack": "^3.10.0"
},
"description": ""
}
After making a fresh directory, copying in your code as is, I get the following:
Error: EACCES: permission denied, mkdir '/build'
at Error (native)
It's trying to access the root level /build directory (which doesn't exist, at least for me).
Tweaking the config a bit more leads to this:
const path = require('path')
module.exports = {
entry : ['./app/index.js'],
output : {
// Get the path including the current directory node is running in
path : path.resolve(__dirname, './build'),
filename: 'bundle.js'
}
}
Which spits out a successful bundle.
There were no errors? Any output at all?
Related
I build a webpack to my project which using firebase 9 to collect page data from documents which is working like a charm in my index.html page. My problem is when i try to add another html page for admin panel it doesn't work my problem is if i am right i need to change my webpack.config.js but don't know how. my webpack.config.js is
const path = require('path')
module.exports = {
mode: 'development',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
watch: true
}
my goal is add another page which is adminpanel.html and use it same as index.html everything controls from index.js in index.html and with watch: true i can see everything in real time please help me
my package.json is
{
"name": "firebase-9",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^5.67.0",
"webpack-cli": "^4.9.2"
},
"dependencies": {
"firebase": "^9.6.4"
}
}
my project structure is
--dist
-adminpanel.html
-index.html
-bundle.js
--node_modules
--src
-index.js
package-lock.json
package.json
webpack.config.js
I'm trying to output an ESM module with WebPack 5. My understanding is that this feature has been added in version 5, and is used by specifying {output: libraryTarget: 'module'}} and {experiments: {outputModule: true}}.
I believe that what I'm seeing is just a WebPack bug - perhaps related to outputModule still being experimental, but I'm not very well versed in WebPack so could easily have missed something.
I get an error 'return' outside of function. With the configuration below, this happens when I run npx webpack. If I change mode to 'development', then it generates a bundle which indeed has a return statement at the end such that attempting to use it generates a similar error at runtime.
webpack.config.js:
const path = require('path');
module.exports = {
entry: "./index.js",
resolve: { extensions: ['.js'] },
//using 'production' rather than 'development' catches error earlier.
mode: 'production',
experiments: {
outputModule: true
},
output: {
filename: 'hello.js',
libraryTarget: "module",
path: path.resolve(__dirname, 'dist')
}
}
index.js
export default function() { return 42; }
package.json
{
"name": "webpackTest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"webpack": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^5.5.1",
"webpack-cli": "^4.2.0"
}
}
I have a new project and setup webpack to use as a module bundler but when I start the webpack-dev-server using npm start script , I got an error
Error can't find module :
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
at Function.Module._load (internal/modules/cjs/loader.js:497:25)
at Module.require (internal/modules/cjs/loader.js:626:17)
at require (internal/modules/cjs/helpers.js:20:18)
although I wrote everything correct and I don't get the point of why this happened ? can any one tell me why this happen ?
this is my package.json file
{
"name": "simple-webpack-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --config ./webapck.common.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"css-loader": "^1.0.0",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.4.1",
"style-loader": "^0.21.0",
"webpack": "^4.15.1",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.4"
}
}
and this is my webpack.common.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin') ;
module.exports = {
entry:{
index:'./src/index.js',
app:'./src/app.js'
},
output: {
path: path.join(__dirname,'dist'),
filename: "[name].js"
},
module: {
rules: [
{
test :/\.css$/,
use:['style-loader','css-loader']
}
]
},
plugins: [
new HtmlWebpackPlugin(
{
chunks:['app'],
template:'./index.html'
}
)
],
devServer: {
port:4000
}
}
I tried your project setup in my IDE and I think I found the solution of your problem , I think you wrote the wrong config name in package.json file
your file in the disk called webpack.common.js
the file name in package.json webapck.common.js
so to solve the problem
change the file name in package.json to webpack.common.js instead of webapck.common.js this will solve the problem I think , change the package.json start script to
"start": "webpack-dev-server --config ./webpack.common.js"
I'm need to use webpack as a script (not the typical config file) and be able to support css imports, however webpack/style-loader does't seem to be able to load a css import when it's outside the root directory.
directoryA/package.json
{
"name": "poc",
"version": "1.0.0",
"description": "",
"main": "poc.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"style-loader": "^0.28.8",
"style-loader": "^0.19.1",
"webpack": "^3.10.0"
}
}
directoryA/poc.js
const path = require("path");
const webpack = require("webpack");
let appPath = process.env.PWD;
webpack({
entry: path.join(appPath, 'app.js'),
context: appPath,
output: {
libraryTarget: 'umd',
path: path.join(appPath, 'out'),
filename: 'app.js'
},
module: {
rules: [
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
}
}).run(() => {
console.log("done");
});
directoryB/app.js
import './foo.css';
directoryB/foo.css
body { background-color: blue; }
directoryB/out/index.html
<html>
<head><script src="app.js"></script></head>
<body></body>
</html>
steps to replicate:
cd directoryB/
node ../directoryA/poc.js
then open directoryB/out/index.html in the browser
result: "Error: Cannot find module "./foo.css"
expected: loading css style and getting a blue page
Note that, if out/index.html , app.js and foo.cs are inside directoryA instead, then running node poc.js actually yields the expected result, however outside, webpack or style-loader can't seem to find the file (note: also tried to use the modules: directive. both cases work if using importing a js file)
setting up a new project that will have multiple grunt tasks that I want to load from task files.
when running my first task, 'core' which is supposed to build the core css for the site, I'm getting an error that I can't seem to resolve. been doing some googling and not finding this specific issue. any issues with the same error message usually were the result of a typo or misplaced curly braces on the part of the OP. Not sure that's the case here, but perhaps someone else sees what I'm obviously not seeing.
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: require('./package.json')
});
grunt.loadTasks('grunt-tasks');
};
grunt-tasks/grunt-core.js
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-sass');
grunt.config('core', {
sass : {
options : {
sourceMap : true,
includePaths : 'node_modules/bootstrap-sass/assets/stylesheets'
},
dist : {
files : {
'main.css' : 'main.scss'
}
}
}
});
grunt.registerTask('core', ['sass:dist']);
};
error:
$ grunt core
Running "sass:dist" (sass) task
Verifying property sass.dist exists in config...ERROR
>> Unable to process task.
Warning: Required config property "sass.dist" missing. Use --force to continue.
Aborted due to warnings.
I've tried a few different things. If I change the registerTask to this:
grunt.registerTask('core', ['sass']);
I get this error:
$ grunt core
>> No "sass" targets found.
Warning: Task "sass" failed. Use --force to continue.
Aborted due to warnings.
not sure if this is relevant, but here is package.json and some specs on the system I'm using.
Mac OSX Yosemite
node version v5.10.1
npm 3.8.3
package.json
{
"name": "TEST",
"version": "1.0.0",
"description": "test test test",
"main": "Gruntfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/path/to/repo"
},
"author": "me <me#example.com>",
"license": "ISC",
"bugs": {
"url": "https://github.com/path/to/repo/issues"
},
"homepage": "https://github.com/path/to/repo",
"devDependencies": {
"angular": "^1.5.5",
"bootstrap-sass": "^3.3.6",
"grunt": "^1.0.1",
"grunt-contrib-jshint": "^1.0.0",
"grunt-contrib-uglify": "^1.0.1",
"grunt-contrib-watch": "^1.0.0",
"grunt-sass": "^1.1.0",
"jquery": "^2.2.3",
"sass-lint": "^1.5.1"
},
"dependencies": {
"jquery": "^2.2.3"
}
}
Looks like it was user error on my part.
in the task file, I had grunt.config(), but I should have had grunt.initConfig()
var taskConfig = {
sass : {
options : {
sourceMap : true,
includePaths : 'node_modules/bootstrap-sass/assets/stylesheets'
},
dist : {
files : {
'main.css' : 'main.scss'
}
}
},
concat : {
core : {
src : ['node_modules/jquery/dist/jquery.js', 'js/main.js'],
dest : "../dev/js/main.js"
}
}
};
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-sass');
grunt.initConfig(taskConfig);
grunt.registerTask('core', ['concat:core','sass']);
};