Cypress Github Actions showing peer dependency conflict errors - npm

I'm trying to set up a workflow to run automated cypress tests in GitHub Actions but continue to run into this error message
npm ERR! While resolving: cypress-plugin-snapshots#1.4.4
npm ERR! Found: cypress#8.4.1
npm ERR! node_modules/cypress
npm ERR! dev cypress#"^8.4.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer cypress#"^4.5.0" from cypress-plugin-snapshots#1.4.4
npm ERR! node_modules/cypress-plugin-snapshots
npm ERR! dev cypress-plugin-snapshots#"1.4.4" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: cypress#4.12.1
npm ERR! node_modules/cypress
npm ERR! peer cypress#"^4.5.0" from cypress-plugin-snapshots#1.4.4
npm ERR! node_modules/cypress-plugin-snapshots
npm ERR! dev cypress-plugin-snapshots#"1.4.4" from the root project
I don't have permission to embed images, but here's a screenshot of the entire error message
Relevant section of the YAML workflow:
jobs:
cypress-run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v3
- name: Cypress Run
uses: cypress-io/github-action#v4
with:
build: npm run build
start: npm start
spec: cypress/integration/example.js
package.json:
{
"name": "cypressautomations",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"cypress:open": "cypress open",
"cypress:debug": "cross-env CYPRESS_REMOTE_DEBUGGING_PORT=9222 cypress open",
"delete-mochawesome-folder": "rm -f mochawesome-report/*.json",
"e2e_mochawesome": "yarn cypress run --spec cypress/integration/Tests/*.js",
"merge-json": "npx mochawesome-merge --reportDir mochawesome-report > mochawesome1.json",
"html-generator": " npx mochawesome-report-generator mochawesome1.json"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#cypress/snapshot": "2.1.7",
"cross-env": "7.0.3",
"cypress": "^8.4.1",
"cypress-fail-on-console-error": "2.0.6",
"cypress-multi-reporters": "1.4.0",
"cypress-plugin-snapshots": "1.4.4",
"cypress-wait-until": "1.7.1",
"eslint": "7.26.0"
},
"dependencies": {
"#azure/cosmos": "3.10.5",
"bson-ext": "4.0.1",
"dotenv": "8.2.0",
"kerberos": "1.1.7",
"lodash": "4.17.21",
"mocha-junit-reporter": "2.0.0",
"mochawesome": "6.2.2",
"mochawesome-merge": "4.2.0",
"mochawesome-report-generator": "5.2.0",
"mongodb": "4.1.2",
"mongodb-client-encryption": "1.2.7"
},
"peerDependencies": {
"mocha": "3.1.2"
}
}
I tried doing a run with the --legacy-peer-deps flag by adding the following code after the "Checkout" step
- name: Install Dependencies
run: npm ci --legacy-peer-deps
but the error persists. It looks like the 'Cypress Run' action runs the 'npm ci' command as part of its own workflow, even if dependencies are already installed.
Any insight into this problem would be greatly appreciated.

I was running into the same issue and figured the same thing with the Cypress Run command. It's doing the npm installation for you.
I fixed this by separating the installation from the action and build, as well as setting the action installation as false:
steps:
- name: Checkout
uses: actions/checkout#v2
# Install NPM dependencies, cache them correctly
# and run all Cypress tests
- name: Cypress install
run: npm install --legacy-peer-deps
- name: Cypress run
uses: cypress-io/github-action#v2
with:
install: false
build: npm run build
start: npm start
run: npm run dev
Cypress is now running my E2E tests.

Related

Failure to install node modules within react native app in a mono repo using pnpm

i'm attempting to run a react native app in a monorepo using pnpm. I added it to pnpm-workspace.yaml file defined as:
packages:
- "apps/*"
When i attempt to run npm i or pnpm i i kept getting the error below:
> sample_project#0.0.1 prepare
> cd .. && husky install frontend/.husky
line 2: husky: command not found
I have husky defined in the root folder(within pnpm-workspace.yaml). Also i declared a .npmrc file that included node-linker=hoisted but still no luck. I also ran pnpm i within the root directory but failed to install node_modules dir within the mobile directory. Please help needed. How does one run a react native app within a monorepo with pnpm? Any help will be appreciated.
Edit
I have husky defined in the root directory as:
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
cd frontend
pnpm run pre-commit
and in my package.json file:
{
"name": "sample_project",
"version": "0.0.1",
"private": true,
"workspaces": [
"apps/*",
"packages/*"
],
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev --parallel",
"test": "turbo run test",
"test:lint": "turbo run test:lint",
"fix": "turbo run fix",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"prepare": "cd .. && husky install frontend/.husky",
"pre-commit": "turbo run fix"
},
"devDependencies": {
"prettier": "latest",
"turbo": "latest",
"husky": "latest",
"lint-staged": "latest"
},
"engines": {
"npm": ">=7.0.0",
"node": ">=14.0.0"
},
"packageManager": "pnpm#7.0.1"
}
When i run the command npm i --loglevel verbose within the mobile directory below is the following errors:
> sample_project#0.0.1 prepare
> cd .. && husky install frontend/.husky
/var/folders/r5/n6lp6wsj2c52h51xxsdgw7y00000gn/T/prepare6589946269.sh: line 2: husky: command not found
npm timing command:i Completed in 54463ms
npm verb stack Error: command failed
npm verb stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/#npmcli/promise-spawn/lib/index.js:63:27)
npm verb stack at ChildProcess.emit (node:events:513:28)
npm verb stack at maybeClose (node:internal/child_process:1091:16)
npm verb stack at ChildProcess._handle.onexit (node:internal/child_process:302:5)
npm verb pkgid ***#0.0.1
npm verb cwd /Users/***/***/***/***/***/****
npm verb Darwin 21.5.0
npm verb node v18.6.0
npm verb npm v8.13.2
npm ERR! code 127
npm ERR! path /Users/***/***/***/***
npm ERR! command failed
npm ERR! command sh -c /var/folders/r5/n6lp6wsj2c52h51xxsdgw7y00000gn/T/prepare6589946269.sh
npm verb exit 127
npm timing npm Completed in 54564ms
npm verb code 127

What is the reason for getting "Error: not supported" when trying to run chai mocha tests in GitLab Ci/Cd pipeline?

I am trying to run a very simple mocha test in a GitLab Ci/Cd pipeline.
My application uses nodejs, express and typescript.
The directory structure looks like this:
- root
- backend
- src
- index.ts
- tests
- chai
- index.ts
- Dockerfile
- nodedemon
- package.json
- package_lock.json
- tsconfig.json
- .gitlab-ci.yml
- docker-compose.yml
With src/index.ts creating the express server.
chai/index.ts looks like this:
import chaiHttp from "chai-http";
import chai from "chai";
import {app} from "../../index";
chai.use(chaiHttp);
// Test base route to return string
describe("Base Route Test", () => {
it(`should return a html file`, () => {
return chai.request(app).get("/")
.then(res => {
chai.expect(res).to.be.html
})
})
})
The nodemon file looks like this:
{
"watch": ["src"],
"ext": ".ts",
"ignore": [],
"exec": "ts-node ./src/index.ts"
}
Dockerfile:
FROM node:16.13.0
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8008
RUN npm run build
ENTRYPOINT ["npm", "run", "start"]
docker-compose.yml:
version: '3.0'
services:
mongo:
image: mongo
container_name: cargonaut_mongo
ports:
- "27017:27017"
node:
build: ./backend
container_name: cargonaut
ports:
- "8008:8008"
depends_on:
- mongo
environment:
- "NODE_ENV=${NODE_ENV}"
and package.json (gitlab-instance and name censored using --):
{
"name": "cargonaut",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon",
"build": "npx tsc",
"test": "mocha -r ts-node/register src/tests/chai/index.ts"
},
"repository": {
"type": "git",
"url": "git#-------:-----/cargonaut.git"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#types/config": "^0.0.41",
"#types/cors": "^2.8.12",
"#types/express": "^4.17.13",
"#types/mocha": "^9.1.1",
"#typescript-eslint/eslint-plugin": "^5.27.0",
"#typescript-eslint/parser": "^5.27.0",
"eslint": "^8.18.0",
"nodemon": "^2.0.16",
"ts-node": "^10.8.0",
"typescript": "^4.7.2"
},
"dependencies": {
"#babel/types": "^7.18.4",
"#types/chai": "^4.3.1",
"#types/express-session": "^1.17.4",
"#types/node": "^18.0.0",
"body-parser": "^1.20.0",
"chai": "^4.3.6",
"chai-http": "^4.3.0",
"config": "^3.3.7",
"cors": "^2.8.5",
"express": "^4.18.1",
"express-session": "^1.17.3",
"json5": "^2.2.1",
"mocha": "^10.0.0",
"mongoose": "^6.4.0"
}
}
And finally, the gitlab-ci.yml:
docker build:
stage: build
tags:
- npm
before_script:
- cd backend
- npm install
script:
- NODE_ENV=test_docker_free npm run test
This commands work on my computer, but if I push to my repo, the pipeline fails with the following output:
$ NODE_ENV=test_docker_free npm run test
npm info it worked if it ends with ok
npm info using npm#6.9.0
npm info using node#v10.16.1
npm info lifecycle cargonaut#1.0.0~pretest: cargonaut#1.0.0
npm info lifecycle cargonaut#1.0.0~test: cargonaut#1.0.0
> cargonaut#1.0.0 test /builds/----/cargonaut/backend
> mocha -r ts-node/register src/tests/chai/index.ts
✖ ERROR: Error: Not supported
at formattedImport (/builds/----/cargonaut/backend/node_modules/mocha/lib/nodejs/esm-utils.js:30:3)
at exports.requireOrImport (/builds/----/cargonaut/backend/node_modules/mocha/lib/nodejs/esm-utils.js:38:34)
at exports.handleRequires (/builds/----/cargonaut/backend/node_modules/mocha/lib/cli/run-helpers.js:94:34)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm info lifecycle cargonaut#1.0.0~test: Failed to exec test script
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cargonaut#1.0.0 test: mocha -r ts-node/register src/tests/chai/index.ts
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cargonaut#1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm timing npm Completed in 469ms
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-06-26T09_56_58_783Z-debug.log
Cleaning up project directory and file based variables 00:01
ERROR: Job failed: exit code 1
I found this bug report: https://github.com/mochajs/mocha/issues/4652 but I am not sure if it is relevant in my case, since I use mocha 10.00 and node v16.13.0 and the issue seems to affect older versions.
So what is the reason for the error? Is there a way to fix it?
Upgrade Node JS to the latest version. The following worked for me:
curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
sudo apt-get install -y nodejs
I seems the problem is not in the code: my universities GitLab runners are very outdated.
So if somebody has the same problem, checking the node version your GitLab runner uses might be worth a try.
Sadly, there is not much for me to do to solve this issue. I can only switch to GitHub.
just install NodeJS from v16.17.0, no more error ;))

NPM: npm peer dependency conflict

I download a project and it has no package-lock.json file.When I run npm install , there is conflict. The error message:
root#fb3391c63c7f:/app/avatar/avatar-h5# npm install --registry=https://registry.npm.taobao.org
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: avatar#3.2.0
npm ERR! Found: vue#2.6.10
npm ERR! node_modules/vue
npm ERR! vue#"2.6.10" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer vue#"3.0.5" from #vue/compiler-sfc#3.0.5
npm ERR! node_modules/#vue/compiler-sfc
npm ERR! peer #vue/compiler-sfc#"^3.0.0-beta.14" from #vue/cli-service#4.5.10
npm ERR! node_modules/#vue/cli-service
npm ERR! peer #vue/cli-service#"^3.0.0 || ^4.0.0-0" from #vue/cli-plugin-babel#4.4.4
npm ERR! node_modules/#vue/cli-plugin-babel
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /root/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-01-18T21_53_07_044Z-debug.log
I read a lot docs and figure out that #vue/cli-plugin-babel#4.4.4 will install lastest #vue/cli-service#4.5.10 .
How can I install it compatible with vue#2.6.10
package.json file
{
"name": "avatar",
"version": "3.2.0",
"scripts": {
"dev": "vue-cli-service serve",
"build:prod": "vue-cli-service build",
"build:stage": "vue-cli-service build --mode staging",
"preview": "node build/index.js --preview",
"lint": "eslint --ext .js,.vue src",
"test:unit": "jest --clearCache && vue-cli-service test:unit",
"test:ci": "npm run lint && npm run test:unit",
"svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml",
"new": "plop"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"src/**/*.{js,vue}": [
"eslint --fix",
"git add"
]
},
"keywords": [
"vue",
"admin",
"dashboard",
"element-ui",
"boilerplate",
"admin-template",
"management-system"
],
"repository": {
"type": "git",
"url": "https://gitee.com/fairyfleet/avatar.git"
},
"dependencies": {
"#riophae/vue-treeselect": "0.4.0",
"axios": "0.18.1",
"clipboard": "2.0.4",
"core-js": "3.6.5",
"echarts": "4.2.1",
"element-ui": "2.13.2",
"file-saver": "2.0.1",
"js-beautify": "1.10.2",
"fuse.js": "3.4.4",
"js-cookie": "2.2.0",
"jsencrypt": "3.0.0-rc.1",
"normalize.css": "7.0.0",
"nprogress": "0.2.0",
"path-to-regexp": "2.4.0",
"screenfull": "4.2.0",
"sortablejs": "1.8.4",
"vue": "2.6.10",
"vue-count-to": "1.0.13",
"quill": "1.3.7",
"vue-cropper": "0.4.9",
"vue-router": "3.0.2",
"vue-splitpane": "1.0.4",
"vuedraggable": "2.20.0",
"vuex": "3.1.0"
},
"devDependencies": {
"#vue/cli-plugin-babel": "4.4.4",
"#vue/cli-plugin-eslint": "4.4.4",
"#vue/cli-plugin-unit-jest": "4.4.4",
"#vue/cli-service": "4.4.4",
"#vue/test-utils": "1.0.0-beta.29",
"autoprefixer": "9.5.1",
"babel-eslint": "10.1.0",
"babel-jest": "23.6.0",
"babel-plugin-dynamic-import-node": "2.3.3",
"chalk": "2.4.2",
"chokidar": "2.1.5",
"connect": "3.6.6",
"eslint": "6.7.2",
"eslint-plugin-vue": "6.2.2",
"html-webpack-plugin": "3.2.0",
"husky": "1.3.1",
"lint-staged": "8.1.5",
"mockjs": "1.0.1-beta3",
"plop": "2.3.0",
"runjs": "4.3.2",
"node-sass": "4.14.1",
"sass-loader": "8.0.2",
"script-ext-html-webpack-plugin": "2.1.3",
"script-loader": "0.7.2",
"serve-static": "1.13.2",
"svg-sprite-loader": "4.1.3",
"svgo": "1.2.0",
"vue-template-compiler": "2.6.10"
},
"engines": {
"node": ">=8.9",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}
Same issue here. It occurs only on newer versions of npm. You can temporarily fix it by falling back on the LTS 14.15 version of NodeJS.
On Linux/MacOS:
nvm use --lts
Or else:
npm install -g npm#6.14.8
What fixed this issue for me was simply removing the node_modules folder and then pasting the package versions in the package json file and running npm install.
To add to Chaim Zonnenberg
I encountered this error when working on a NestJS project on macOS with Node (16.11.1) and npm (8.0.0).
When I run the command npm install I get the error below:
npm WARN old lockfile
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: admin-gateway#0.0.1
npm ERR! Found: rxjs#7.3.0
npm ERR! node_modules/rxjs
npm ERR! rxjs#"^6.0.0" from the root project
npm ERR! peer rxjs#"^6.0.0 || ^7.0.0" from #nestjs/axios#0.0.1
npm ERR! node_modules/#nestjs/axios
npm ERR! #nestjs/axios#"^0.0.1" from the root project
npm ERR! 4 more (#nestjs/common, #nestjs/core, #nestjs/config, #nestjs/microservices)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! elastic-apm-nest#"0.0.7" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: rxjs#6.6.7
npm ERR! node_modules/rxjs
npm ERR! peer rxjs#"^6.0.0" from elastic-apm-nest#0.0.7
npm ERR! node_modules/elastic-apm-nest
npm ERR! elastic-apm-nest#"0.0.7" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
Here's how I fixed it:
The issue was that I was running a newer version of Node (16.11.1) which was not the long term support (lts) version.
First, I removed the node package that was present on my macOS using the homebrew command:
brew uninstall --ignore-dependencies node
And then I installed nvm using homebrew:
brew install nvm
Next, I created the NVM's working directory since it didn't exist:
mkdir ~/.nvm
Next, I added the following to the ~/.zshrc file or your desired shell
configuration file. For me the ~/.zshrc file did not exist so I created it using the command touch ~/.zshrc, and then opened it using the command:
nano ~/.zshrc
and added the following below:
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
Save the file using the key combinations Ctrl + X and then Y and the ENTER
Next, open a new terminal, and install Node LTS version using the command:
nvm install --lts
If you already have the Node LTS version installed then run the command:
nvm use --lts
Confirm your Node and npm versions using the command:
node --version
npm --version
Finally, run the npm install command again, and this time everything will go fine.
That's all
npm install -g npm#6.14.8
this also works on windows.

How to publish my npm package in GitLab NPM Registry?

I hooked up a trial gold plan to test GitLab NPM Registry functionality.
Created a gitlab prohect with the name "bar".
Created a file to generate a token: in the file with the name auth.txt I wrote the line:
grant_type=password&username=my-gitlab-username& password=my-gitlab-password
Generated a token using the command:
curl -d "# auth.txt" -X POST http:/gitlab.com/oauth/token
In the .npmrc file, the path was indicated
gitlab.com/api/v4/projects/my-gitlab-project-id/packages/npm/:_ authToken=my-genereated-token
Created an app.js file for testing, with the contents: console.log('test')
Created a json package with content
{
"name": "#foo/bar",
"version": "1.0.0",
"description": "",
"main": "app.js",
"dependencies": {
"express": "^4.16.4"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
"author": "",
"license": "ISC",
"publishConfig": {
"registry":"http://gitlab.com/api/v4/projects/my-gitlab-project-id/packages/npm/"
}
}
6.In the folder now there are 3 files:
.npmrc
app.js
package.json
I start publishing the package to the repository with the command
npm --verbose publish
It is not published! writes:
npm verb cli [ '/usr/bin/node', '/usr/local/bin/npm', '--verbose', 'publish' ]
npm info using npm#6.14.2
npm info using node#v13.11.0
npm verb npm-session febf284b8dfbe40b
npm verb publish [ '.' ]
npm info lifecycle #foo/bar#1.0.0~prepublish: #foo/bar#1.0.0
npm info lifecycle #foo/bar#1.0.0~prepare: #foo/bar#1.0.0
npm info lifecycle #foo/bar#1.0.0~prepublishOnly: #foo/bar#1.0.0
npm info lifecycle #foo/bar#1.0.0~prepack: #foo/bar#1.0.0
npm info lifecycle #foo/bar#1.0.0~postpack: #foo/bar#1.0.0
npm notice
npm notice 📦 #foo/bar#1.0.0
npm notice === Tarball Contents ===
npm notice 687B logs
npm notice 175B app.js
npm notice 404B package.json
npm notice 582B README.md
npm notice 55B auth.loc.txt
npm notice 59B auth.txt
npm notice === Tarball Details ===
npm notice name: #foo/bar
npm notice version: 1.0.0
npm notice package size: 1.1 kB
npm notice unpacked size: 2.0 kB
npm notice shasum: c4220955014b80c6948ff2a20124ac8d145d0675
npm notice integrity: sha512-pOQJVaXuneH80[...]DdtCjSLD1vkDQ==
npm notice total files: 6
npm notice
npm http fetch PUT 301 http://gitlab.com/api/v4/projects/my-gitlab-project-id/packages/npm/#foo%2fbar 283ms
npm info lifecycle #foo/bar#1.0.0~publish: #foo/bar#1.0.0
npm info lifecycle #foo/bar#1.0.0~postpublish: #foo/bar#1.0.0
#foo/bar#1.0.0
npm verb exit [ 0, true ]
npm timing npm Completed in 555ms
npm info ok
But in the GitLab in the list on the left - in Packages > List not a single package is displayed, either in the All section or in the NPM section.
Please help me figure out what I'm doing wrong.
You can try to specify the package registry for the exact project.
.npmrc file example:
# Set URL for your scoped packages.
#foo:registry=https://gitlab.com/api/v4/projects/<Source Project ID>/packages/npm/
# Add the token for the scoped packages URL. This will allow you to download
//gitlab.com/api/v4/projects/<Source Project ID>/packages/npm/:_authToken=${CI_JOB_TOKEN}
# with the project you want your package to be uploaded to.
//gitlab.com/api/v4/projects/<Destination Project ID>/packages/npm/:_authToken=${CI_JOB_TOKEN}

npm run build - Insufficient number of arguments or no entry found

I am trying to build a project for the first time and I am getting an error message.
Insufficient number of arguments or no entry found.
Alternatively, run 'webpack(-cli) --help' for usage info.
Hash: 83fdf40d8aadb2841816
Version: webpack 4.18.0
Time: 180ms
Built at: 09/11/2018 4:55:53 AM
ERROR in Entry module not found: Error: Can't resolve './src' in '/home/baudhi/website'
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! website#15.19.1 build: `webpack --mode production`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the website#15.19.1 build 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! /home/baudhi/.npm/_logs/2018-09-11T11_55_53_650Z-debug.log
The ebook I am reading has asked me to type 'npm run build' but it is not working. any help pls.
My package.json file looks like the following:
{
"name": "website",
"version": "15.19.1",
"description": "just practice",
"main": "main.js",
"scripts": {
"develop": "webpack --mode development --watch",
"build": "webpack --mode production"
},
"author": "pebaudhi",
"license": "ISC",
"devDependencies": {
"webpack": "^4.18.0",
"webpack-cli": "^3.1.0"
},
"dependencies": {
"jquery": "^3.3.1"
}
}
And my directory structure is:
/usr/baudhi/website/.babelrc
/usr/baudhi/website/package.json
/usr/baudhi/website/jquery-3.3.1.js
/usr/baudhi/website/src/main.js
/usr/baudhi/website/dist/main.js
node -v
v10.7.0
Thank you very much for helping me.
If you're using Webpack 4 the configuration has been defaulted. Hence, you don't need to provide a webpack.config.json file but you're project needs to follow the default config.
The default entry point in Webpack 4 is ./src/index.js. So either rename ./src/main.js or create webpack.config.js file with the following minimum.
module.exports = {
entry: './src/main.js'
};