I've been working on this app locally with Next.js. It deploys and builds fine locally, but I'm having issues getting it to work when deploying it to Fleek and Vercel.
On Fleek, I have configured the deploy and build settings for a Next.js app, but I'm still running into this issue.
When I try to deploy and build to the live server on Fleek, I get the following error.
2:39:21 PM 12/11/2022: Failed to compile.
2:39:21 PM 12/11/2022: ./components/Pool.js
2:39:21 PM 12/11/2022: Module not found: Can't resolve './Withdraw' in '/workspace/components'
2:39:21 PM 12/11/2022: Import trace for requested module:
2:39:21 PM 12/11/2022: ./pages/Stake.js
2:39:21 PM 12/11/2022: > Build failed because of webpack errors
2:39:21 PM 12/11/2022: error Command failed with exit code 1.
The next.config.js file:
/** #type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
eslint: {
ignoreDuringBuilds: true,
},
resolve: {
extensions: ["", ".js", ".jsx"],
},
}
module.exports = nextConfig
The package.json file:
{
"name": "gwin-app",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"#headlessui/react": "^1.6.6",
"#heroicons/react": "^1.0.6",
"moralis": "^1.9.0",
"next": "12.2.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hot-toast": "^2.3.0",
"react-moralis": "^1.4.0",
"tw-elements": "^1.0.0-alpha12",
"web3": "^1.7.5",
"web3uikit": "^0.1.170"
},
"devDependencies": {
"autoprefixer": "^10.4.7",
"eslint": "8.20.0",
"eslint-config-next": "12.2.2",
"postcss": "^8.4.14",
"tailwindcss": "^3.1.6"
}
}
Here is the import in Pool.js
import Withdraw from "./Withdraw"
Withdraw.js looks like this
#imports
const Withdraw = ({
#props
}) => {
#stuff
}
export default Withdraw
I've tried:
ignoring eslint in the next.config.js.
changing the path for Withdraw.js from '../components/Withdraw' to './Withdraw' (Pool.js and Withdraw.js are both in the components folder). I thought maybe a different path would help.
yarn build && yarn start (locally, which works)
Checking that component is "Withdraw" and "Withdraw.js" is the file.
resolving ext. in next.config.js
This is a case sensitivity issue with git and operating systems.
Find more info here https://github.com/vercel/next.js/issues/9482 .
#jamesmosier pointed out the following:
Try changing the name of the file completely and test again. There can be case sensitivity issues with git and operating systems, especially if you commit a file as one case (i.e. componentOne.js) and then change it later (to something like ComponentOne.js). If that works, commit that new file name and then you can change it back to the original filename and commit that again.
This error is very hard to spot, because there is no indication of anything wrong in the IDE, everything appears to be 100% correct, but behind the scenes there are case sensitivity issues.
So do the following:
Rename the module Withdraw.js and all of the references to something
entirely new
Commit the changes
Rename everything back to the desired names and commit/push your changes
After that, the issue is resolved and the app deploys.
Related
I have a Next.js + Sanity.io project and when I deploy from local build using vercel CLI with
vercel build and then vercel deploy --prebuilt, it works great.
However, when I do vercel --prod to create production deployment, it keeps failing.
The log goes:
[16:48:49.455] Previous build cache not available
[16:48:49.684] Downloading 69 deployment files...
[16:48:50.586] Running "vercel build"
[16:48:51.246] Vercel CLI 28.10.0
[16:48:51.661] Installing dependencies...
[16:48:52.107] yarn install v1.22.17
[16:48:52.183] [1/4] Resolving packages...
[16:48:52.393] [2/4] Fetching packages...
[16:49:16.863] [3/4] Linking dependencies...
[16:49:31.972] [4/4] Building fresh packages...
[16:49:32.468] Done in 40.37s.
[16:49:32.503] Detected Next.js version: 13.1.1-canary.1
[16:49:32.505] Running "yarn run build"
[16:49:32.842] yarn run v1.22.17
[16:49:32.888] $ next build
[16:49:33.425] Attention: Next.js now collects completely anonymous telemetry regarding usage.
[16:49:33.425] This information is used to shape Next.js' roadmap and prioritize features.
[16:49:33.425] 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:
[16:49:33.425] https://nextjs.org/telemetry
[16:49:33.426]
[16:49:33.588] info - Linting and checking validity of types...
[16:49:38.211] Failed to compile.
[16:49:38.212]
[16:49:38.212] ./sanity/sanity.cli.ts:1:31
[16:49:38.212] Type error: Cannot find module 'sanity/cli' or its corresponding type declarations.
[16:49:38.212]
[16:49:38.213] [0m[31m[1m>[22m[39m[90m 1 | [39m[36mimport[39m {defineCliConfig} [36mfrom[39m [32m'sanity/cli'[39m[0m
[16:49:38.213] [0m [90m | [39m [31m[1m^[22m[39m[0m
[16:49:38.213] [0m [90m 2 | [39m[0m
[16:49:38.213] [0m [90m 3 | [39m[36mexport[39m [36mdefault[39m defineCliConfig({[0m
[16:49:38.213] [0m [90m 4 | [39m api[33m:[39m {[0m
[16:49:38.253] error Command failed with exit code 1.
[16:49:38.254] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[16:49:38.283] Error: Command "yarn run build" exited with 1
my package.json:
{
"name": "portfolio-project",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"#portabletext/react": "^2.0.0",
"#sanity/image-url": "^1.0.1",
"#types/node": "18.11.12",
"#types/react": "18.0.26",
"#types/react-dom": "18.0.9",
"#vercel/analytics": "^0.1.6",
"eslint": "8.29.0",
"eslint-config-next": "13.0.6",
"framer-motion": "^7.6.19",
"next": "13.0.6",
"next-sanity": "^3.1.5",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-simple-typewriter": "^5.0.1",
"react-social-icons": "^5.15.0",
"typescript": "4.9.4"
},
"devDependencies": {
"autoprefixer": "^10.4.13",
"postcss": "^8.4.19",
"tailwind-scrollbar": "^2.0.1",
"tailwindcss": "^3.2.4"
}
}
sanity package.json in the sanity folder:
{
"name": "portfolio-project",
"private": true,
"version": "1.0.0",
"main": "package.json",
"license": "UNLICENSED",
"scripts": {
"dev": "sanity dev",
"start": "sanity start",
"build": "sanity build",
"deploy": "sanity deploy",
"deploy-graphql": "sanity graphql deploy"
},
"keywords": [
"sanity"
],
"dependencies": {
"#sanity/vision": "^3.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-is": "^18.2.0",
"sanity": "^3.0.0",
"styled-components": "^5.2.0"
},
"devDependencies": {
"#sanity/eslint-config-studio": "^2.0.1",
"eslint": "^8.6.0",
"prettier": "^2.8.1",
"typescript": "^4.0.0"
},
"prettier": {
"semi": false,
"printWidth": 100,
"bracketSpacing": false,
"singleQuote": true
}
}
Anyone having the same problem?
It keeps saying it cannot find module 'sanity/cli' or its corresponding type declarations.
I've tried upgrading Next.js version to the latest (next#canary) as somebody suggested, installing #sanity/cli to the local and etc, but found no luck.
If anyone has a clue, please help!!!
What solved my case was to add this to next.config.js
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true
},
typescript: {
// !! WARN !!
// Dangerously allow production builds to successfully complete even if
// your project has type errors.
// !! WARN !!
ignoreBuildErrors: true
}
Be mindful that this does not break anything in your code. I think it maybe is because of having a NextJS project with typescript and the Sanity project aswell. Or maybe because it is not installing still the dependencies of Sanity package.json when doing a next build.
Having almost similar problem, except that for me, it does not even work for vercel build
I posted the same question didn't find an answer yet. Even editing Next.config.js not works for me
Problem Deploying a Next JS + Sanity Project to Vercel
I was trying to get this setup to work for a while and there is no support or similar issues over the web. There is actually one closed topic on Local community but no solution at all.
So, my setup is:
Local by Flywheel server for WordPress
VS Code with Node installed
#wordpress/scripts to bundle all my CSS and JS files
browser-sync to live reload
Here is my .json file:
{
"name": "mywebsite",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"live": "npm-run-all --parallel sync start",
"sync": "browser-sync start -p 'mywebsite.local' --files '**/*.php' 'build/*.js' 'build/*.css'",
"build": "wp-scripts build",
"start": "wp-scripts start",
"dev": "wp-scripts start",
"devFast": "wp-scripts start",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#wordpress/scripts": "*",
"browser-sync": "^2.27.9",
"node-sass": "^7.0.1",
"normalize.css": "^8.0.1",
"npm-run-all": "^4.1.5"
}
}
So, the Browser Sync starts nicely in the command line, when starting it opens a new browser windows with this Error below.
There is nothing in the Local's log as they advice on this error screen.
Do anyone encounters similar problems and have the knowledge how to fix that?
I would be super grateful for any hints, walkarounds or solutions or maybe someone can share the other simple setup ideas to achieve the live reload functionality?
I had the same issue, it comes from the combination of npm-run-all and browser-sync. Instead of using npm-run-all, I used browser-sync as a webpack plugin.
Install browser-sync-webpack-plugin
npm install browser-sync-webpack-plugin -D
Then add browser-sync-webpack-plugin as plugin in your webpack.config.js file. As you use #wordpress/scripts, your config will be :
const defaultConfig = require( '#wordpress/scripts/config/webpack.config' );
const BrowserSyncPlugin = require('browser-sync-webpack-plugin')
module.exports = {
...defaultConfig,
plugins: [
...defaultConfig.plugins,
new BrowserSyncPlugin({
// browse to http://localhost:3000/ during development,
// ./public directory is being served
host: 'localhost',
port: 3000,
proxy: 'http://YOURDOMAIN.local/'
})
]
};
Take care to replace YOURDOMAIN.
Now when you run :
npm start
browser-sync will be automatically launched.
I have a Nextjs app using jest and react-testing-library for the test, I add the .eslintrc file with npx .eslintrc --init command to my project.
whenever I lint my project, I get the following error:
.eslintrc.js:
module.exports = {
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:#typescript-eslint/recommended",
"plugin:#typescript-eslint/recommended-requiring-type-checking",
"next",
"next/core-web-vitals"
],
"parser": "#typescript-eslint/parser",
"parserOptions": {
"project":"./tsconfig.json",
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
}
};
and error:
info - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
Error: Failed to load config "next" to extend from.
Referenced from: D:\web\reactjs\react-testing\react-testing-app\.eslintrc.js
Resolved, after installing this package, the code will run without error:
npm i --save-dev eslint-config-next
For a misterious reason running npm audit fix --force changed my package.json from:
"eslint-config-next": "12.0.1"
to:
"eslint-config-next": "^0.2.4"
I had to change it manually and the error went away.
I am trying to deploy my Storybook on Netlify, I'm using Next.js framework but it fails every time and I don't know what is wrong
Netlify configuration :
Build command: npm run build-storybook
Publish directory: storybook-static
My package.json:
{
"homepage": "https://github.com/alexCoding42/tailwind-storybook",
"name": "tailwind-storybook",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"dependencies": {
"next": "10.0.9",
"react": "17.0.1",
"react-dom": "17.0.1"
},
"devDependencies": {
"#babel/core": "^7.13.10",
"#netlify/plugin-nextjs": "^3.0.3",
"#storybook/addon-actions": "^6.2.0-alpha.22",
"#storybook/addon-essentials": "^6.2.0-alpha.22",
"#storybook/addon-links": "^6.2.0-alpha.22",
"#storybook/react": "^6.2.0-alpha.22",
"#types/node": "^14.14.35",
"#types/react": "^17.0.3",
"babel-loader": "^8.2.2",
"gh-pages": "^3.1.0",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-preset-env": "^6.7.0",
"prettier": "^2.2.1",
"tailwindcss": "^2.0.4",
"typescript": "^4.2.3"
}
}
The error I get on Netlify:
Plugin "#netlify/plugin-nextjs" internal error
Error: No static assets found in .next dist (aka no /.next/static). Please check your project configuration. Your next.config.js must be one of serverless or experimental-serverless-trace. Your build command should include next build.
I have also tried to add a netlify.toml at the root of my project with this config:
[build]
command = "npm run build-storybook"
publish = "storybook-static"
[[plugins]]
package = "#netlify/plugin-nextjs"
And added #netlify/plugin-nextjsas dev dependency of package.json but I get the same error...
Can someone help me on this please ?
I had a similar problem but not with the storybook but with nx + nextjs.
If I tried to deploy the app to the netlify I got the same error.
So I changed next.config.js in the root directory and add to distDir path to generated .static folder and it's working now.
and this is my netlify.toml ss
The Netlify Next.js plugin isn't required for a Storybook build. In fact, no plugins are required; the only configuration needed is, as OP says:
Build command: npm run build-storybook
Publish directory: storybook-static
Or, in netlify.toml:
[build]
command = "npm run build-storybook"
publish = "storybook-static"
No [[plugins]] fields are needed.
If Netlify is configured through the UI, go to https://app.netlify.com/sites/my-awesome-site/plugins and remove the Next.JS plugin.
I have been getting this error for days now and I am not sure how to fix it.
When I run the "dev" package in Node Task Runner Explorer it gives this error.
It seems to be something to do with different versions of node and webpack not getting along. the error message, and my packages.json file are below, as is the link to the article I am working through.
setting-up-a-react-environment-for-aspnet-mvc-44la
Error Message
C:\DevFolder\MyApplication> cmd.exe /c npm run dev --color=always
asp.net#1.0.0 dev C:\DevFolder\MyApplication
webpack --mode development --watch C:\DevFolder\MyApplication\node_modules\webpack\bin\webpack.js:90 let
notify = ^^^ SyntaxError: Block-scoped declarations (let, const,
function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:430:10)
at startup (node.js:141:18)
at node.js:980:3 npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! asp.net#1.0.0 dev: `webpack --mode development --watch` npm ERR!
Exit status 1 npm ERR! npm ERR! Failed at the asp.net#1.0.0 dev
script. npm ERR! This is probably not a problem with npm. There is
likely additional logging output above.
package.json
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"scripts": {
"build": "webpack",
"dev": "webpack --mode development --watch"
},
"devDependencies": {
"#babel/cli": "^7.7.5",
"#babel/core": "^7.7.5",
"#babel/plugin-proposal-class-properties": "^7.7.4",
"#babel/preset-env": "^7.7.6",
"#babel/preset-react": "^7.7.4",
"babel-loader": "^8.0.6",
"browser-sync": "^2.26.7",
"browser-sync-webpack-plugin": "^2.2.2",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-notifier": "^1.8.0"
},
"dependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0",
"npm": "6.12.1",
"node" : "5.3.0"
}
}
Webpack Config
"use strict";
var path = require("path");
var WebpackNotifierPlugin = require("webpack-notifier");
var BrowserSyncPlugin = require("browser-sync-webpack-plugin");
module.exports = {
entry: "./Scripts/ApplicationReact/ApplicationReact.js",
output: {
path: path.resolve(__dirname, "./Scripts/"),
filename: "bundle.js"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
},
devtool: "inline-source-map",
plugins: [new WebpackNotifierPlugin(), new BrowserSyncPlugin()]
};
Summary
Don't install the Node.js nuget package, it breaks your project and it will remain broken after you have removed it. Just let the general installation of node do the work.
Detail
When in any other directory, if I did "node -v" in the command line and it would return version 12.13.1
When in my project folder if I did "node -v" it would return 5.3.0
When I removed the Node.js nuget package I thought it would default to the system version but instead it just said "cannot find the file or command specified" (or something along those lines).
I had copied the whole of our software to another folder for the purposes of this exercise. I just branched to another folder and this time the "node -v" was coming back with 12.13.1
I carried on with the exercise and the error did not appear. I am not sure how to fix it once you get into this state.
Better answers?
This isn't a great answer and I won't mark it as the answer. If anyone can provide a plausible explanation for what is going on here, and a way to cure your project from the nuget node lurgy, I will mark it as the answer.