Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

idcreatv's avatar

Moved a Laravel 8 app to another domain and now 'npm run prod' is broken?

Hello all, I was wondering if someone can help me with a strange issue I've come across.

I've moved a copy of my Laravel 8 app to another domain on the same VPS and while the install seems to have worked perfectly (regarding functionality etc) I seem to have an issue when running npm run prod.

On the original domain I can run this without any issues. Having zipped an archive of the original app (as a backup), I've extracted it into the correct directory. The files are identical apart from the tweaks I've made to the .env file for the app name and database, as well as the app config file.

When I run npm run prod I get this error (server path and domain name removed):

[XXXXXXXXX@dXXXXXXXXX XXXXXXXXX]$ npm run prod

> @ prod /home/XXXXXXXXX/XXXXXXXXX.co.uk/XXXXXXXXX
> npm run production


> @ production /home/XXXXXXXXX/XXXXXXXXX.co.uk/XXXXXXXXX
> mix --production

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

Error: Cannot find module '../package.json'
Require stack:
- /home/XXXXXXXXX/XXXXXXXXX.co.uk/XXXXXXXXX/node_modules/.bin/mix
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1029:15)
    at Function.Module._load (internal/modules/cjs/loader.js:898:27)
    at Module.require (internal/modules/cjs/loader.js:1089:19)
    at require (internal/modules/cjs/helpers.js:73:18)
    at Object.<anonymous> (/home/XXXXXXXXX/XXXXXXXXX.co.uk/XXXXXXXXX/node_modules/.bin/mix:8:13)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/XXXXXXXXX/XXXXXXXXX.co.uk/XXXXXXXXX/node_modules/.bin/mix'
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ production: `mix --production`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ production 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/XXXXXXXXX/.npm/_logs/2022-07-19T16_17_35_623Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ prod: `npm run production`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ prod 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/XXXXXXXXX/.npm/_logs/2022-07-19T16_17_35_639Z-debug.log

When I checked the log, I got this:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/home/XXXXXXXXX/.nvm/versions/node/v14.4.0/bin/node',
1 verbose cli   '/home/XXXXXXXXX/.nvm/versions/node/v14.4.0/bin/npm',
1 verbose cli   'run',
1 verbose cli   'prod'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'preprod', 'prod', 'postprod' ]
5 info lifecycle @~preprod: @
6 info lifecycle @~prod: @
7 verbose lifecycle @~prod: unsafe-perm in lifecycle true
8 verbose lifecycle @~prod: PATH: /home/XXXXXXXXX/.nvm/versions/node/v14.4.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXX/node_modules/.bin:/home/XXXXXXXXX/.nvm/versions/node/v14.4.0/bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/cpanel/composer/bin:/home/XXXXXXXXX/.local/bin:/home/XXXXXXXXX/bin
9 verbose lifecycle @~prod: CWD: /home/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXX
10 silly lifecycle @~prod: Args: [ '-c', 'npm run production' ]
11 silly lifecycle @~prod: Returned: code: 1  signal: null
12 info lifecycle @~prod: Failed to exec prod script
13 verbose stack Error: @ prod: `npm run production`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/home/XXXXXXXXX/.nvm/versions/node/v14.4.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (/home/XXXXXXXXX/.nvm/versions/node/v14.4.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1051:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
14 verbose pkgid @
15 verbose cwd /home/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXX
16 verbose Linux 3.10.0-1160.42.2.vz7.184.10
17 verbose argv "/home/XXXXXXXXX/.nvm/versions/node/v14.4.0/bin/node" "/home/XXXXXXXXX/.nvm/versions/node/v14.4.0/bin/npm" "run" "prod"
18 verbose node v14.4.0
19 verbose npm  v6.14.5
20 error code ELIFECYCLE
21 error errno 1
22 error @ prod: `npm run production`
22 error Exit status 1
23 error Failed at the @ prod script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Unfortunately I'm not that technically minded when it comes to the 'behind the scenes' things - does anyone have any ideas why I'm getting this issue?

I've cleared all the caches etc, checked the permissions and the setup (inc php8.1) is identical to the original domain and they're both on the same VPS which is running AlmaLinux 8 with plenty of ram and CPUs - I just cannot find what is stopping it. Knowing me, its probably something really simple!

Thanks in advance for any help!

0 likes
7 replies
Sinnbeck's avatar

Can you show us what you have? Package.json and mix config. And can you run npm install?

idcreatv's avatar

@Sinnbeck Sure, package.json is this…

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "mix",
        "watch": "mix watch",
        "watch-poll": "mix watch -- --watch-options-poll=1000",
        "hot": "mix watch --hot",
        "prod": "npm run production",
        "production": "mix --production"
    },
    "devDependencies": {
        "@tailwindcss/aspect-ratio": "^0.4.0",
        "@tailwindcss/forms": "^0.4.0",
        "alpinejs": "^2.7.3",
        "autoprefixer": "^10.4.2",
        "axios": "^0.21.4",
        "browser-sync": "^2.27.7",
        "browser-sync-webpack-plugin": "^2.3.0",
        "laravel-mix": "^6.0.41",
        "lodash": "^4.17.19",
        "postcss": "^8.4.5",
        "postcss-import": "^12.0.1",
        "resolve-url-loader": "^4.0.0",
        "sass": "^1.49.0",
        "sass-loader": "^12.4.0",
        "tailwindcss": "^3.0.17"
    },
    "dependencies": {
        "@fortawesome/fontawesome-free": "^5.15.4",
        "chart.js": "^3.8.0",
        "daisyui": "^1.25.4",
        "tailwind-scrollbar-hide": "^1.1.7"
    }
}

webpack.mix.js is this…

const mix = require('laravel-mix');

/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel applications. By default, we are compiling the CSS
| file for the application as well as bundling up all the JS files.
|
*/

mix.js('resources/js/app.js', 'public/js').postCss('resources/css/app.css', 'public/css', [
    require('postcss-import'),
    require('tailwindcss'),
    require('autoprefixer'),
])
.scripts([
    'public/js/app.js',
    'public/js/jquery-3.5.1.min.js',
    'public/js/jquery-ui-1.12.1/jquery-ui.min.js',
    'public/js/js.cookie.min.js',
    'public/js/collect.min.js',
    'public/js/moment.min.js',
    'public/js/sweetalert2/dist/sweetalert2.all.min.js',
    'public/js/wow.min.js',
    'public/js/slick/slick.min.js',
    'public/js/chart.min.js',
  ], 'public/js/merged-header.js')
.scripts([
    'public/js/yall.min.js',
    'public/js/splide407/dist/js/splide.min.js',
  ], 'public/js/merged-footer.js')
.styles([
    'public/css/fontawesome-5-9-0/css/all.css',
    'public/js/jquery-ui-themes-1.12.1/themes/base/jquery-ui.css',
    'public/css/app.css',
    'public/css/animate.min.css',
    'public/js/slick/slick-theme.css',
    ], 'public/css/merged.css')

.minify(['public/css/merged.css', 'public/js/merged-header.js', 'public/js/merged-footer.js']);

mix.webpackConfig({
    plugins: [
        // ...
    ],
    resolve: {
       // ...
    },
    stats: {
         children: true
    }
});

I had run npm install earlier, this was the result…

audited 947 packages in 5.424s

89 packages are looking for funding
  run `npm fund` for details

found 16 vulnerabilities (9 moderate, 4 high, 3 critical)
  run `npm audit fix` to fix them, or `npm audit` for details

When I ran npm audit fix I got this…

npm ERR! code EEXIST
npm ERR! path /home/XXXXXXX/XXXXXXX.co.uk/XXXXXXX/node_modules/.bin/browser-sync
npm ERR! Refusing to delete /home/XXXXXXX/XXXXXXX.co.uk/XXXXXXX/node_modules/.bin/browser-sync: is outside /home/XXXXXXX/XXXXXXX.co.uk/XXXXXXX/node_modules/browser-sync and not a link
npm ERR! File exists: /home/XXXXXXX/XXXXXXX.co.uk/XXXXXXX/node_modules/.bin/browser-sync
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

Its the exact same setup as the other version which is working fine with no errors. Weird.

Sinnbeck's avatar

@idcreatv ok. I notice it tries to go down a level to get package.json? Is your folder structure different than usual?

Cannot find module '../package.json'
idcreatv's avatar

@Sinnbeck Its the default structure (I'd never mess around with that), only addition being my changelog file:

app
php.ini
artisan
phpunit.xml
bootstrap 
public
_CHANGELOG.txt 
README.md
composer.json
resources
composer.lock
routes
config
server.php
database 
storage
tailwind.config.json
node_modules
tests
package.json
vendor
package-lock.json
webpack.mix.js
bljdavidson's avatar
Level 14

Seems like a platform issue. You could try deleting the package-lock.json and the node_modules directory then resinstall them with npm install.

There might be a platform setting you could use in the package.json file but I'm not too sure.

1 like
idcreatv's avatar

@bljdavidson That did the trick! Thanks, it was driving me mad. Another note to add to my 'check before posting; list!

1 like

Please or to participate in this conversation.