1
votes

I tried to use this tutorial, to install webpack to asp.net core project

https://codeburst.io/how-to-use-webpack-in-asp-net-core-projects-a-basic-react-template-sample-25a3681a5fc2

Here is command in my package.json

 {
 "name": "streamline",
 "version": "1.0.0",
 "description": "",
 "main": "index.js",
 "scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "wbp": "webpack wwwroot/source/app.js wwwroot/dist/bundle.js"
 },
 "keywords": [],
 "author": "",
 "license": "ISC",
 "devDependencies": {
  "webpack": "^4.16.0",
  "webpack-command": "^0.4.1"
 }
}

But when I run it with npm run wbp I get this

internal/modules/cjs/loader.js:596 throw err; ^

Error: Cannot find module 'import-local' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15) at Function.Module._load (internal/modules/cjs/loader.js:520:25) at Module.require (internal/modules/cjs/loader.js:650:17) at require (internal/modules/cjs/helpers.js:20:18) at Object. (/Users/nemesises/Documents/GitHub/streamline/Streamline/node_modules/webpack-command/lib/cli.js:11:21) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] wbp: webpack wwwroot/source/app.js wwwroot/dist/bundle.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] wbp script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR!
/Users/nemesises/.npm/_logs/2018-07-13T14_21_24_555Z-debug.log

How I can fix it?

UPDATE

After I make this

"wbp": "webpack --entry wwwroot/source/app.js --output wwwroot/dist/bundle.js"

Reinstall npm packages and try to run command

I got this error

ERROR in Entry module not found: Error: Can't resolve 'wwwroot/source/app.js' in '/Users/nemesises/Documents/GitHub/streamline/StreamLine' npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! [email protected] wbp: webpack --entry wwwroot/source/app.js --output wwwroot/dist/bundle.js npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the [email protected] wbp script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR!
/Users/nemesises/.npm/_logs/2018-07-14T19_45_54_642Z-debug.log

But I got this file in my folder!

If I use my old command and create dist/bundle.js it works, but bundle.js is empty

4

4 Answers

0
votes

webpack --entry wwwroot/source/app.js --output wwwroot/dist/bundle.js

--entry says what is the entry

--output what to output to

0
votes

It seems like npm has failed to install the dependencies properly. Try to reinstall the local packages by executing the following commands in your package.json directory:

rm -rf node_modules npm install

If everything goes fine with npm install you should be able to run npm run wbp successfully.

0
votes

I'm currently digging my way into this ASP.NET CORE + Webpack + Script combo. Luckily, I've found my solution, hope this can fit your case. Take a look at my package.json

{
  "name": "blindforced",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "wbp": "webpack --mode production wwwroot/source/app.js --output wwwroot/dist/bundle.js",
    "dev": "webpack --mode development wwwroot/assets/app.js --output wwwroot/dist/bundle.js",
    "build": "webpack --mode production wwwroot/assets/app.js --output wwwroot/dist/bundle.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^4.29.6",
    "webpack-cli": "^3.2.3"
  }
}
0
votes

this worked for me: webpack --entry ./wwwroot/source/app.js --output wwwroot/dist/bundle.js, note ./ in ./wwwroot.