Why I can't find out build folder after runing npm run build on a nextjs project? - reactjs

I have created a project using Nextjs framework.
When I run the project using npm run dev command, My project runs properly, and it's okay.
But when I run the command npm run build to build a project, After that, I can't find a build folder.
Bellow is the full report which is a builder shown to me:
λ npm run build
dastshafa-final#0.1.0 build
next build
info - Checking validity of types
./pages/cartProcess/index.js 13:6 Warning: React Hook useEffect has a
missing dependency: 'displayNavbar'. Either include it or remove the
dependenc y array. If 'displayNavbar' changes too often, find the
parent component that defines it and wrap that definition in use
Callback. react-hooks/exhaustive-deps 31:11 Warning: Do not use
. Use Image from 'next/image' instead. See:
https://nextjs.org/docs/messages/no-img-elem ent
#next/next/no-img-element
./pages/index.js 14:6 Warning: React Hook useEffect has a missing
dependency: 'setDisplayNavbar'. Either include it or remove the depend
ency array. If 'setDisplayNavbar' changes too often, find the parent
component that defines it and wrap that definition in useCallback.
react-hooks/exhaustive-deps
./components/navbar.js 58:21 Warning: Do not use . Use Image
from 'next/image' instead. See:
https://nextjs.org/docs/messages/no-img-elem ent
#next/next/no-img-element 101:17 Warning: passHref is missing. See:
https://nextjs.org/docs/messages/link-passhref
#next/next/link-passhref 117:9 Warning: passHref is missing. See:
https://nextjs.org/docs/messages/link-passhref
#next/next/link-passhref 118:11 Warning: Do not use . Use Image
from 'next/image' instead. See:
https://nextjs.org/docs/messages/no-img-ele ment
#next/next/no-img-element 118:11 Warning: img elements must have an
alt prop, either with meaningful text, or an empty string for
decorative imag es. jsx-a11y/alt-text
./components/productDetail.js 72:6 Warning: React Hook useMemo has a
missing dependency: 'productDetail'. Either include it or remove the
dependency array. react-hooks/exhaustive-deps 106:15 Warning: Do not
use . Use Image from 'next/image' instead. See:
https://nextjs.org/docs/messages/no-img-ele ment
#next/next/no-img-element 106:15 Warning: img elements must have an
alt prop, either with meaningful text, or an empty string for
decorative imag es. jsx-a11y/alt-text
./components/productItem.js 18:7 Warning: Do not use . Use Image
from 'next/image' instead. See:
https://nextjs.org/docs/messages/no-img-eleme nt
#next/next/no-img-element
./components/products.js 21:6 Warning: React Hook useEffect has a
missing dependency: 'dispatch'. Either include it or remove the
dependency arr ay. react-hooks/exhaustive-deps
./components/sort.js 37:6 Warning: React Hook useEffect has a missing
dependency: 'dispatch'. Either include it or remove the dependency arr
ay. react-hooks/exhaustive-deps 41:6 Warning: React Hook useEffect
has a missing dependency: 'filterProducts'. Either include it or
remove the dependen cy array. If 'filterProducts' changes too often,
find the parent component that defines it and wrap that definition in
u seCallback. react-hooks/exhaustive-deps
info - Need to disable some ESLint rules? Learn more here:
https://nextjs.org/docs/basic-features/eslint#disabling-rule s info -
Creating an optimized production build info - Compiled successfully
info - Collecting page data info - Generating static pages (4/4)
info - Finalizing page optimization
Page Size First Load JS ┌ ○
/ 6.37 kB 144 kB ├ └
css/b7d3c6e158495aa9.css 962 B ├ /_app
0 B 129 kB ├ ○ /404 194
B 129 kB ├ ○ /cartProcess 1.45 kB
130 kB ├ └ css/da339555cb6d6d6b.css 233 B └ λ
/product/[...params] 10.4 kB 148 kB
└ css/f78802d3b8b60c2b.css 2.98 kB
First Load JS shared by all 129 kB ├ chunks/framework-5f4595e5518b5600.js 42 kB ├
chunks/main-a054bbf31fb90f6a.js 27.6 kB ├
chunks/pages/_app-26dcf6f0f3b3e602.js 57.2 kB ├
chunks/webpack-62757ff16512d194.js 1.81 kB └
css/70cd855905d78aa0.css 24.4 kB
λ (Server) server-side renders at runtime (uses getInitialProps or
getServerSideProps) ○ (Static) automatically rendered as static HTML
(uses no initial props)
What is the problem? How can I fix it?

Look for a directory named .next which is the default the build command outputs to.
You can set a custom directory (for example build) by adding it to the distDir key in next.config.js:
const nextConfig = {
distDir: "build",
};
module.exports = nextConfig;
If you're exporting your app to static HTML, the export command outputs to a directory named out.

Related

How to make a unique layout for the main page?

I have multiple pages on my web-site and only main page should have a different layout? How can I achieve this?
src/
- page1/ <- LayoutB
- page2/ <- LayoutB
- page3/ <- LayoutB
- index.svelte <- LayoutA
If I use __layout.svelte in the src/ folder it will apply for every page.
Update November 2022
This approach was tested in
npm -v #sveltejs/kit
8.19.2
To make a unique layout for a specific page (or group of pages) you need to use group.
src/
routes/
(unauthenticated)/
welcome/
register/
login/
+page.svelte
+layout.svelte (this layout applies to welcome/, register/ and login/
(authenicated)/
home/
settings/
+page.svelte
+layout.svelte (this layout applies to home/, settings/ and dashboard/
+page.svelte
+layout.svelte (this layout applies to all pages in unauthenticated/ and authenticated/)
I was able to find a solution by using named layouts from SvelteKit
The solution to my problem will look like this
src/
- page1/ <- LayoutB
- page2/ <- LayoutB
- page3/ <- LayoutB
- __layout.svelte (LayoutB)
- __layout-main.svelte (LayoutA)
- index#main.svelte <- LayoutA
I created a layout file with -main suffix and used this name as a reference to the layout in my index#main.svelte file

SassError: can't properly access theme-color()

Full Error:
Failed to compile.
./src/#core/scss/react/libs/noui-slider/noui-slider.scss (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-0-1!./node_modules/postcss-loader/src??postcss!./node_modules/sass-loader/dist/cjs.js??ref--5-oneOf-0-3!./node_modules/sass-loader/dist/cjs.js??ref--5-oneOf-0-4!./src/#core/scss/react/libs/noui-slider/noui-slider.scss)
SassError: $color: theme-color("primary") is not a color.
╷
23 │ "lighten-5": lighten(theme-color("primary"), 25%),
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
╵
src/#core/scss/base/core/colors/palette-variables.scss 23:18 #import
src/#core/scss/base/core/colors/palette-noui.scss 11:9 #import
src/#core/scss/react/libs/noui-slider/noui-slider.scss 3:9 root stylesheet
To be clear, once I switched all occurrences of theme-color("primary") to the actual color(#0074d9, blue color I found from Bootstrap documentation which is the supposed primary color) across the SCSS files, it then gave me the same error for theme-color("secondary") which were in proceeding lines of the files. I'm working off a template and this is the import at the top of the files this error is coming from:
// Overrides user _variables-components
#import '../../bootstrap-extended/include';
This leads to the following file presumably made by the template maker:
// Functions
#import 'bootstrap/scss/functions'; // Bootstrap core function
#import 'functions'; // Bootstrap extended function
// Variables
#import 'scss/variables/variables'; // Bootstrap custom variable override (for user purpose)
#import 'variables'; // Bootstrap extended variable override
#import 'bootstrap/scss/variables'; // Bootstrap core variable
// Mixins
#import 'bootstrap/scss/mixins'; // Bootstrap core mixins
#import 'mixins'; // Bootstrap extended mixins
package.json:
"bootstrap": "5.1.3",
"sass-loader": "^12.2.0"
Maybe I should downgrade bootstrap? Should I try to override the variables that don't work in my palette-variables.scss file under $theme-colors like some articles recommend despite the theme already trying to do that?
I haven't yet gotten this react project up and running locally, which is the goal, and this seems to be the last group of errors to plow through before getting the development server running since when running npm start it'd say "starting up the development server", open up localhost:3000 and almost work.
I just used yarn to install the modules and everything worked completely fine.

How to use Codemod(Next.js)? Invalid transform choice

I tried to apply codemod on my pages(index.js is inside).
npx #next/codemod pages
npx: installed 440 in 15.252s
Invalid transform choice, pick one of:
- name-default-component
- withamp-to-config
- url-to-withrouter
Directory structure
node_modules
package.json
package-lock.json
pages
How to run codemod?
You need to specify a valid transform before your path.
From Next.js codemod documentation:
Usage
npx #next/codemod <transform> <path>
transform - name of transform, see available transforms below.
path - files or directory to transform
--dry Do a dry-run, no code will be edited
--print Prints the changed output for comparison

Gatsby Build stuck on Building Static HTML for Pages

Im trying to build my Gatsby project into production files. When running the command Gatsby build, the process runs and gets stuck at "Building static html for pages"
Terminal:
$ gatsby build
success open and validate gatsby-configs — 0.006 s
success load plugins — 0.419 s
success onPreInit — 0.064 s
success delete html and css files from previous builds — 0.257 s
success initialize cache — 0.006 s
success copy gatsby files — 0.061 s
success onPreBootstrap — 0.010 s
success source and transform nodes — 0.155 s
success building schema — 0.173 s
success createPages — 0.000 s
success createPagesStatefully — 0.047 s
success onPreExtractQueries — 0.004 s
success update schema — 0.022 s
warning Using the global `graphql` tag is deprecated, and will not be supported in v3.
Import it instead like: import { graphql } from 'gatsby' in file:
/website/src/components/image.js
success extract queries from components — 0.266 s
success run static queries — 0.229 s — 6/6 26.29 queries/second
success run page queries — 0.003 s — 2/2 902.62 queries/second
success write out page data — 0.004 s
success write out redirect data — 0.001 s
success onPostBootstrap — 0.000 s
info bootstrap finished - 4.846 s
success Building production JavaScript and CSS bundles — 8.720 s
⡀ Building static HTML for pages{ department: 'obj1',
numEmployees: 2,
avgHrs: 18,
avgRate: 15,
other: 200 }
{ department: 'obj2',
numEmployees: 4,
avgHrs: 17,
avgRate: 13,
other: 150 }
{ department: 'obj3',
numEmployees: 3,
avgHrs: 20,
avgRate: 22,
other: 250 }
[ 'department', 'numEmployees', 'avgHrs', 'avgRate', 'other' ]
0
0
[ 'department', 'numEmployees', 'avgHrs', 'avgRate', 'other' ]
1
1
[ 'department', 'numEmployees', 'avgHrs', 'avgRate', 'other' ]
2
2
undefined
undefined
⢀ Building static HTML for pages /website/public/render-page.js:27034
var el = document.getElementById("myChart" + index);
^
ReferenceError: document is not defined
at charting (/website/public/render-page.js:27034:14)
at Timeout._onTimeout (/website/public/render-page.js:27103:9)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
⠁ Building static HTML for pages
It keeps running, without throwing an error and stopping. I created a Gatsby starter and ran the same command, where it finished building in around 30 seconds. What is preventing my website from building?
The problem here is that on the "server-side", as in, when Gatsby is rendering the pages statically, they are run within an environment that doesn't have a concept of a "window" or a "document", so while your code here might work when it's run inside a browser, it fails here.
A simple trick is to wrap anything that requires there to be a document in an if statement
if(typeof(document) !== 'undefined') { ... } (or your preferred alternative).
There are also components that you can use to wrap chunks of the page, for instance React NoSSR, which does this like so:
import React from 'react';
import NoSSR from 'react-no-ssr';
import MyChart from './MyChart.jsx';
const MyChartPage = () => (
<div>
<h2>My Chart Page</h2>
<hr />
<NoSSR>
<MyChart />
</NoSSR>
</div>
);
When this is rendered server-side, the NoSSR rule ignores rendering, and your code requiring a document runs only on the client-side.

Importing npm linked React JSX project/modules into AngularJS TypeScript module not working

I am working on a proof-of-concept sample React framework/library that could be used in React applications, as well as an AngularJS framework wrapper around it so that it can be used as an AngularJS framework/library as well.
There are 2 projects:
sample-react-framework
sample-react-framework-wrapper (the AngularJS project)
Right now I have an npm link to the sample-react-framework project from the sample-react-framework-wrapper project.
sample-react-framework has 3 components - a navigation bar, banner, and side menu. These components are .jsx files.
sample-react-framework-wrapper has 3 components as well - the same 3 - which are just .ts wrappers that render the React elements.
I'm trying to import my React JSX modules into the TypeScript modules, and it appears to be working but is then throwing an error at the end anyway:
webpack result is served from http://localhost:8090/assets
content is served from C:\workspaces\UI\sample-react-framework-wrapper
10% 0/1 build modulests-loader: Using typescript#1.6.2
Hash: c4f0160d96f95001f727
Version: webpack 1.12.2
Time: 3233ms
Asset Size Chunks Chunk Names
sample.framework.js 42.5 kB 0 [emitted] main
chunk {0} sample.framework.js (main) 39.6 kB [rendered]
[0] ./src/components/index.ts 112 bytes {0} [built]
[1] ./src/components/banner/banner.ts 2.44 kB {0} [built] [1 error]
[3] ../sample-react-framework/src/index.js 862 bytes {0} [built]
[4] ../sample-react-framework/src/components/banner/banner.jsx 8.64 kB {0} [built]
[5] ../sample-react-framework/~/classnames/index.js 1.12 kB {0} [built]
[6] ../sample-react-framework/src/components/side-menu/side-menu.jsx 11.7 kB {0} [built]
[7] ../sample-react-framework/src/components/navigation/navigation.jsx 9.81 kB {0} [built]
[8] ./src/components/navigation/navigation.ts 2.37 kB {0} [built] [1 error]
[10] ./src/components/side-menu/side-menu.ts 2.44 kB {0} [built] [1 error]
+ 2 hidden modules
ERROR in ./src/components/side-menu/side-menu.ts
(7,26): error TS2307: Cannot find module 'sample-react-framework'.
ERROR in ./src/components/navigation/navigation.ts
(7,28): error TS2307: Cannot find module 'sample-react-framework'.
ERROR in ./src/components/banner/banner.ts
(6,24): error TS2307: Cannot find module 'sample-react-framework'.
If you look above you can see it was able to get into and build the JSX files fine - but still throws errors that it can't find my framework in the end.
I've tried different things from Googling around, such as setting a resolve.fallback to be my path.join(__dirname, 'node_modules') - but that also failed (tried things from this issue: https://github.com/webpack/webpack/issues/784)
Unfortunately I'm really not sure what else to try at this point :(
Here's an example of how I am defining the JSX classes:
import React from 'react';
import classNames from 'classnames';
import SideMenu from '../side-menu/side-menu';
class Banner extends React.Component {
}
module.exports = Banner;
And the TS module:
/// <reference path="../../../typings/angularjs/angular.d.ts" />
/// <reference path="../../../typings/react/react.d.ts" />
import * as React from 'react';
import { Banner } from 'sample-react-framework';
angular
.module('sampleFramework.banner', [])
.directive('bannerComponent', bannerComponent);
function bannerComponent() {
return {
restrict: 'E',
scope: {
banner: '=',
links: '='
},
replace: true,
...
}
}
Does anyone have any idea what could be causing this?
I also posted an issue looking for help on the ts-loader project's GitHub issues: https://github.com/TypeStrong/ts-loader/issues/72
jbrantly got back to me quickly and informed me that the issue was I needed to define a typings file for my react framework in order for TypeScript to understand it - oops!
From your SO question:
import { Banner } from 'sample-react-framework';
The error here is that TypeScript is saying it doesn't understand sample-react-framework. TypeScript doesn't understand plain JS modules. It only understands TS modules or declaration files that describe the API of the JS module. Assuming you want to keep sample-react-framework as pure JS and not TypeScript, you'll need to create a definition file for it. For example...
// index.d.ts
import React from 'react';
export class Banner extends React.Component { }
Then in the package.json of sample-react-framework you could put:
"typings": "index.d.ts"
TypeScript should then be able to resolve the definition file and understand what you mean when you say import { Banner } from 'sample-react-framework';.
I've tested it out and defined the following index.d.ts in sample-react-framework:
import * as React from 'react';
interface Props { }
interface State { }
export class Banner extends React.Component<Props, State> { }
export class SideMenu extends React.Component<Props, State> { }
export class Navigation extends React.Component<Props, State> { }
The TS compiler was complaining about React.Component not matching the definition (and the React import not being '* as React') - but other than those minor tweaks his solution was exactly what I needed to fix my problem.
I've had the same problem. And I've located the problem in both ts-loader and typescript-loader (not in webpack itself) - as both were unable to resolve npm linked modules.
Also I was able to compile same code base with raw TypeScript compiler - which I am using as solution (also because other reasons).
But I think pointing resolve.falback to original/linked source did help.

Resources