I am trying to deploy an app to Vercel, and getting this error at build
14:13:58.168 Cloning github.com/ChrisB007/moodflics (Branch: main, Commit: 7a2acfe)
14:13:58.575 Cloning completed: 406.06ms
14:13:58.624 Analyzing source code...
14:13:59.946 Installing build runtime...
14:14:03.139 Build runtime installed: 3.193s
14:14:07.055 Build cache not provided
14:14:08.517 Installing dependencies...
14:14:09.142 npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion#1, but package-lock.json was generated for lockfileVersion#2. I'll try to do my best with it!
14:14:23.664 npm WARN moodflics#0.1.0 No repository field.
14:14:23.676 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#2.3.2 (node_modules/fsevents):
14:14:23.677 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
14:14:23.681 added 387 packages from 281 contributors in 14.582s
14:14:23.836 62 packages are looking for funding
14:14:23.836 run `npm fund` for details
14:14:23.861 Detected Next.js version: 10.2.0
14:14:23.864 Running "npm run build"
14:14:24.144 > moodflics#0.1.0 build /vercel/path0
14:14:24.144 > next build
14:14:24.557 warn - React 17.0.1 or newer will be required to leverage all of the upcoming features in Next.js 11. Read more: https://nextjs.org/docs/messages/react-version
14:14:24.912 info - Using webpack 5. Reason: no custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
14:14:25.052 info - Checking validity of types...
14:14:25.068 Attention: Next.js now collects completely anonymous telemetry regarding usage.
14:14:25.068 This information is used to shape Next.js' roadmap and prioritize features.
14:14:25.068 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
14:14:25.068 https://nextjs.org/telemetry
14:14:25.123 info - Creating an optimized production build...
14:14:29.905 Failed to compile.
14:14:29.906 ModuleNotFoundError: Module not found: Error: Can't resolve 'next-auth/client' in '/vercel/path0/pages'
14:14:29.906 > Build error occurred
14:14:29.907 Error: > Build failed because of webpack errors
14:14:29.907 at /vercel/path0/node_modules/next/dist/build/index.js:17:924
14:14:29.907 at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/telemetry/trace/trace.js:6:584)
14:14:29.946 npm ERR! code ELIFECYCLE
14:14:29.947 npm ERR! errno 1
14:14:29.951 npm ERR! moodflics#0.1.0 build: `next build`
14:14:29.951 npm ERR! Exit status 1
14:14:29.951 npm ERR!
14:14:29.951 npm ERR! Failed at the moodflics#0.1.0 build script.
14:14:29.951 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
14:14:29.959 npm ERR! A complete log of this run can be found in:
14:14:29.959 npm ERR! /vercel/.npm/_logs/2021-05-10T18_14_29_952Z-debug.log
14:14:29.972 Error: Command "npm run build" exited with 1
Everything seems to be working fine locally, but when I tried deploying it to Vercel I got the above error message. Can you tell me how to fix it?
Sometimes Vercel acts wired that my codes run locally(npm run dev) but fail after upload. This happens when I use Github automatic deployment, i.e. I directly push to my Github repo then Vercel automatically build and update.
However, using Vercel CLI solved my problem. run vercel for preview then vercel --prod for deployment in production
It can't resolve next-auth/client
ModuleNotFoundError: Module not found: Error: Can't resolve 'next-auth/client' in '/vercel/path0/pages'
Ensure that next-auth is properly installed as a dependency and not a dev dependency. Also upgrade your version of react, it's throwing a warning about it not being 17.01 or higher. If you are using typescript, try module augmentation via the next-auth namespace as indicated in their documentation for typescript namespaces. For example, an #/types/next.d.ts file and an #/types/next-auth.d.ts file for module augmentation.
Locally, I use nextauth as well, and have the following in my #/types/next.d.ts file:
import type { NextComponentType, NextPageContext } from 'next';
import type { Session } from 'next-auth';
import type { Router } from 'next/router';
declare module 'next/app' {
type AppProps<P = Record<string, unknown>> = {
Component: NextComponentType<NextPageContext, any, P>;
router: Router;
__N_SSG?: boolean;
__N_SSP?: boolean;
pageProps: P & {
/** Initial session passed in from getServerSideProps or getInitialProps */
session?: Session;
};
};
}
As for the contents of my #/types/next-auth.d.ts file, it's for a custom headless wordpress auth flow, but you can customize the Session/User interfaces regardless of whether you're using a custom approach or not
import NextAuth, { User } from 'next-auth';
import { JWT } from 'next-auth/jwt';
import { WordpressUserPartialFragment } from '../graphql/generated/graphql';
declare module 'next-auth' {
interface Session extends WordpressUserPartialFragment {
response: {
accessToken: string;
id: string;
avatar: {
url: string;
};
description: string | null;
slug: string;
username: string;
email: string;
firstName: string;
lastName: string;
token_exp: string;
refresh_token: string;
locale: string;
};
}
}
Delete node_modules and run yarn install.
Then do yarn build.
If you use npm then do npm i and npm run build instead of yarn install and yarn build.
Then deploy
Check .vercelignore file for folders/files you are missing.
In my case, I have included folder and forgot.
Also double check what source files got synced to vercel, under project deployments, source tab.
Related
I am trying to install a fresh Strapi app on my mac, by running the
npx create-strapi-app#latest my-project --quickstart
commnand. It installs the Strapi app fine, but when I try to run "npm run develop", I get this error:
"Strapi: Middleware "strapi::body": Cannot destructure property 'config' of 'strapi.plugin(...)' as it is undefined."
And the app doesn't start. full error text is as follows:
Middleware "strapi::body": Cannot destructure property 'config' of 'strapi.plugin(...)' as it is undefined.
Error: Middleware "strapi::body": Cannot destructure property 'config' of 'strapi.plugin(...)' as it is undefined.
at instantiateMiddleware (/Users/davit/Github/my-project/node_modules/#strapi/strapi/lib/services/server/middleware.js:12:11)
at resolveMiddlewares (/Users/davit/Github/my-project/node_modules/#strapi/strapi/lib/services/server/middleware.js:56:18)
at registerApplicationMiddlewares (/Users/davit/Github/my-project/node_modules/#strapi/strapi/lib/services/server/register-middlewares.js:66:29)
at async Object.initMiddlewares (/Users/davit/Github/my-project/node_modules/#strapi/strapi/lib/services/server/index.js:99:7)
at async Strapi.bootstrap (/Users/davit/Github/my-project/node_modules/#strapi/strapi/lib/Strapi.js:445:5)
at async Strapi.load (/Users/davit/Github/my-project/node_modules/#strapi/strapi/lib/Strapi.js:457:5)
at async Strapi.start (/Users/davit/Github/my-project/node_modules/#strapi/strapi/lib/Strapi.js:198:9)
Would appreciate any help regarding this issue.
Got the same exception when yarn develop.
Make sure you have right version range for node
node -v if not use nvm use 14.19.1 (or above)
Go to package.json and change strapi version.
from "#strapi/strapi": "^4.3.5" to "#strapi/strapi": "^4.3.6"
Remove package-lock.json and yarn.lock
Run npm install or/and yarn install
I had also posted this question in Strapi forums and it turns out that the problem was with Strapi 4.3.5. They advised updating to 4.3.6 as this issue had been hotfixed. I can confirm that this issue no longer exists on Strapi 4.3.6.
So normally Vercel gives me decent error messages, but this one seems to have no detail. Just
"failed with exit code 1".
For context, I just started this project w the basic NextJS template, made a few modifications, and this is my first deploy.
Failed once and I assumed it was because NextJS has strict type checking on by default, so I modified the next.config.js file as follows (per here):
module.exports = {
typescript: {
// !! WARN !!
// Dangerously allow production builds to successfully complete even if
// your project has type errors.
// !! WARN !!
ignoreBuildErrors: true,
},
};
But still failed. Here is the full log:
10:23:27.575 Cloning github.com/lawderp/physical (Branch: main, Commit: 8f97554)
10:23:28.589 Cloning completed: 1.014s
10:23:28.614 Analyzing source code...
10:23:29.739 Installing build runtime...
10:23:31.612 Build runtime installed: 1.873s
10:23:34.043 Looking up build cache...
10:23:34.164 Build cache found. Downloading...
10:23:35.100 Build cache downloaded [21.48 MB]: 936.007ms
10:23:36.250 Installing dependencies...
10:23:36.489 yarn install v1.22.11
10:23:36.547 [1/4] Resolving packages...
10:23:36.734 success Already up-to-date.
10:23:36.743 Done in 0.26s.
10:23:36.754 Detected Next.js version: 11.1.2
10:23:36.755 Running "yarn run build"
10:23:37.021 yarn run v1.22.11
10:23:37.047 $ next build
10:23:37.820 info - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
10:23:37.976 info - Skipping validation of types...
10:23:40.439 error Command failed with exit code 1.
10:23:40.439 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
10:23:40.456 Error: Command "yarn run build" exited with 1
Still not sure what the issue was but eventually figured out how to get past this - ignored ESLint during build by adding the following to next.config.js:
eslint: {
ignoreDuringBuilds: true,
},
(I don't advise doing this but this was quick low-stakes experiment)
I received the same vague message after making eslint alterations. Locally linting and deployment was successful, however deploying to vercel failed like yours.
Although "ignoreDuringBuilds": "true" in my .eslint.json did band-aid fix the issue, I was able to rollback each eslint change and found that my "linebreak-style": ["error", "windows"] was the underlying issue.
It passed linting locally, but failed on vercel deployment. I've fixed my line-breaks and all works great now without having to ignore during builds.
This question already has an answer here:
Fetch error when building Next.js static website in production
(1 answer)
Closed 12 months ago.
The app fetches data from local Javascript file via an api. Here is below the error and code.
$ npm run build
next-crash-course#0.1.0 build
next build && next export
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist#latest --update-db
info - Creating an optimized production build
info - Compiled successfully
Build error occurred
FetchError: request to http://localhost:3000/api/articles failed, reason: connect ECONNREFUSED 127.0.0.1:3000
at ClientRequest. (C:\WebTest_NextJS(Brad Traversy)\pr1\node_modules\node-fetch\lib\index.js:1461:11)
at ClientRequest.emit (node:events:369:20)
at Socket.socketErrorListener (node:_http_client:462:9)
at Socket.emit (node:events:369:20)
at emitErrorNT (node:internal/streams/destroy:188:8)
at emitErrorCloseNT (node:internal/streams/destroy:153:3)
at processTicksAndRejections (node:internal/process/task_queues:81:21) {
type: 'system',
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED'
}
info - Collecting page data .npm ERR! code 1
npm ERR! path C:\Test_NextJS\pr1
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c next build && next export
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\MH1\AppData\Local\npm-cache_logs\2021-05-21T02_51_47_465Z-debug.log
NOTE: in the dev mode everything work fine.
Code link: https://github.com/bradtraversy/next-crash-course
When we are building with "next export" it will try to invoke the call to fetch the data Pages/index.js line 13. In Config/index.js it is expecting the API server is hosted somewhere "https://yourwebsite.com". As a workaround,
Modify "https://yourwebsite.com" to "http://localhost:3000" inside Config/index.js
Open one terminal and start "npm run dev"
Open 2nd terminal and execute "npm run build". As the API is running in localhost:3000, it will build properly.
Config/index.js
const dev = process.env.NODE_ENV !== 'production'
export const server = dev ? 'http://localhost:3000' : 'https://yourwebsite.com'
Pages/index.js
export const getStaticProps = async () => {
const res = await fetch(`${server}/api/articles`)
const articles = await res.json()
return {
props: {
articles,
},
}
}
URL: https://nextjs.org/docs/advanced-features/static-html-export
Browse the link in any browser. Example: http://localhost:3000/about
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1001 file(s) to forward-jetify. Using 4 workers...
info JS server already running.
info Installing the app...
> Configure project :react-native-firebase_admob
:react-native-firebase_admob package.json found at /home/muhamed-kveshkshaano/suck/node_modules/#react-native-firebase/admob/package.json
:react-native-firebase_app package.json found at /home/muhamed-kveshkshaano/suck/node_modules/#react-native-firebase/app/package.json
:react-native-firebase_admob:firebase.bom using default value: 26.3.0
:react-native-firebase_admob:ads.consent using default value: 1.0.6
:react-native-firebase_admob package.json found at /home/muhamed-kveshkshaano/suck/node_modules/#react-native-firebase/admob/package.json
:react-native-firebase_admob:version set from package.json: 10.5.1 (10,5,1 - 10005001)
:react-native-firebase_admob:android.compileSdk using custom value: 29
:react-native-firebase_admob:android.targetSdk using custom value: 29
:react-native-firebase_admob:android.minSdk using custom value: 16
:react-native-firebase_admob:reactNativeAndroidDir /home/muhamed-kveshkshaano/suck/node_modules/react-native/android
> Configure project :react-native-firebase_app
:react-native-firebase_app package.json found at /home/muhamed-kveshkshaano/suck/node_modules/#react-native-firebase/app/package.json
:react-native-firebase_app:firebase.bom using default value: 26.3.0
:react-native-firebase_app:play.play-services-auth using default value: 19.0.0
:react-native-firebase_app package.json found at /home/muhamed-kveshkshaano/suck/node_modules/#react-native-firebase/app/package.json
:react-native-firebase_app:version set from package.json: 10.5.0 (10,5,0 - 10005000)
:react-native-firebase_app:android.compileSdk using custom value: 29
:react-native-firebase_app:android.targetSdk using custom value: 29
:react-native-firebase_app:android.minSdk using custom value: 16
:react-native-firebase_app:reactNativeAndroidDir /home/muhamed-kveshkshaano/suck/node_modules/react-native/android
> Task :react-native-firebase_app:compileDebugJavaWithJavac
> Task :app:processDebugResources FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
37 actionable tasks: 29 executed, 8 up-to-date
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
/home/muhamed-kveshkshaano/.gradle/caches/transforms-2/files-2.1/820765fbb4c63d086027395fb7f0dacc/play-services-ads-lite-19.6.0/AndroidManifest.xml:27:5-38:15: AAPT: error: unexpected element <queries> found in <manifest>.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 32s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Note: Some input files use or override a deprecated API.
here is the error, the main problem is each i install admob module #react-native-firebase/admob, it throws this error after trying a lot i couldnt find any solution, it only happens after installing admob module except that it build well, anyone knows whats wrong with that module
I was with the same problem and it work for me
in android/app/build.gradle
defaultConfig {
...
multiDexEnabled true // added for admob problem
}
...
dependencies {
...
implementation "androidx.multidex:multidex:2.0.1" // fix firebaseAdmob
}
in android/build.gradle
dependencies {
classpath('com.android.tools.build:gradle:4.1.2')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.3.3'
}
now open the android folder in Android Studio and wait for gradle will update
when finish the gradle update run npx react-native run-android
downgrade all the rnfirebase libraries that you are using to less than 10.0.0 (admob 7.6.11 and app 9.0.0), as I show in the image
how can I add moment.js locale file to serverless bundle?
Thanks for any help :)
I tried the following:
git clone git#github.com:AnomalyInnovations/serverless-nodejs-starter.git
cd serverless-nodejs-starter
npm i moment
then in file handler.js add
import moment from "moment";
and update hello with just call to moment(); (to avoid lint error)
when running local run:
serverless invoke local --function hello
the error received:
Error: Cannot find module './locale'
There seems to be an issue with the latest version of momentjs as you can see in this Github Issue. You can try the following:
npm install --save moment#2.24.0
Add a resolutions block in your package.json file as such:
"resolutions": {
"moment": "2.24.0"
}