Skip to content

Application not running in dev mode #1

@bipinmehta

Description

@bipinmehta

I created next app using npx create-next-app
All files given in here were copied and created in the project.

deleted package.json
npm init
copied dependencies and scripts from this repo into package.json
deleted folder node_modules
npm i
modified script: "dev": nodemon serve.js
Installed missing packages like isomorphic-unfetch and glob
npm run dev

Following output on cli
bipin289@Bipins-MBP next-video-chat % npm run dev

next-video-chat@1.0.0 dev /Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat
nodemon server.js

[nodemon] 2.0.2
[nodemon] to restart at any time, enter rs
[nodemon] watching dir(s): .
[nodemon] watching extensions: js,mjs,json
[nodemon] starting node server.js
/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/next/dist/next-server/server/config.js:8
if(path!=null&&path.length){var _userConfig$amp,_userConfig$experimen;const userConfigModule=require(path);const userConfig=normalizeConfig(phase,userConfigModule.default||userConfigModule);if(Object.keys(userConfig).length===0){Log.warn('Detected next.config.js, no exported configuration found. https://err.sh/vercel/next.js/empty-configuration');}if(userConfig.target&&!targets.includes(userConfig.target)){throw new Error(Specified target is invalid. Provided: "${userConfig.target}" should be one of ${targets.join(', ')});}if((_userConfig$amp=userConfig.amp)!=null&&_userConfig$amp.canonicalBase){const{canonicalBase}=userConfig.amp||{};userConfig.amp=userConfig.amp||{};userConfig.amp.canonicalBase=(canonicalBase.endsWith('/')?canonicalBase.slice(0,-1):canonicalBase)||'';}if((_userConfig$experimen=userConfig.experimental)!=null&&_userConfig$experimen.reactMode&&!reactMo

Error: Specified target is invalid. Provided: "node" should be one of server, serverless, experimental-serverless-trace
at loadConfig (/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/next/dist/next-server/server/config.js:8:417)
at new Server (/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/next/dist/next-server/server/next-server.js:1:4533)
at new DevServer (/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/next/dist/server/next-dev-server.js:1:2964)
at createServer (/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/next/dist/server/next.js:2:607)
at Object. (/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/server.js:8:17)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
at internal/main/run_main_module.js:17:11
[nodemon] app crashed - waiting for file changes before starting...

Please guide to resolve this issue.

next.config.js

const path = require("path");
const glob = require("glob");

module.exports = {
  entry: ["server.js"],
  output: {
    filename: "bundle.js",
  },
  target: "node",
  webpack: (config) => {
    // Fixes npm packages that depend on `fs` module
    config.node = {
      fs: "empty",
    };

    config.module.rules.push(
      {
        test: /\.(css|scss)/,
        loader: "emit-file-loader",
        options: {
          name: "dist/[path][name].[ext]",
        },
      },
      {
        test: /\.css$/,
        use: ["babel-loader", "raw-loader", "postcss-loader"],
      },
      {
        test: /\.s(a|c)ss$/,
        use: [
          "babel-loader",
          "raw-loader",
          "postcss-loader",
          {
            loader: "sass-loader",
            options: {
              includePaths: ["styles", "node_modules"]
                .map((d) => path.join(__dirname, d))
                .map((g) => glob.sync(g))
                .reduce((a, c) => a.concat(c), []),
            },
          },
        ],
      }
    );

    return config;
  },
};

On getting this error, I tried ti build the proj by running: npm run build and got following error:

^C
bipin289@Bipins-MBP next-video-chat % npm run build

next-video-chat@1.0.0 build /Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat
next build

warn - React 17.0.1 or newer will be required to leverage all of the upcoming features in Next.js 11. Read more: https://err.sh/next.js/react-version

Build error occurred
Error: Specified target is invalid. Provided: "node" should be one of server, serverless, experimental-serverless-trace
at loadConfig (/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/next/dist/next-server/server/config.js:8:417)
at /Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/next/dist/build/index.js:2:227
at /Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/next/dist/build/tracer.js:3:360
at NoopTracer.withSpan (/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/@opentelemetry/api/build/src/trace/NoopTracer.js:47:16)
at ProxyTracer.withSpan (/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/@opentelemetry/api/build/src/trace/ProxyTracer.js:36:34)
at traceFn (/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/next/dist/build/tracer.js:3:330)
at /Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/next/dist/build/index.js:2:158
at /Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/next/dist/build/tracer.js:3:476
at NoopTracer.withSpan (/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/@opentelemetry/api/build/src/trace/NoopTracer.js:47:16)
at ProxyTracer.withSpan (/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/@opentelemetry/api/build/src/trace/ProxyTracer.js:36:34)
at traceAsyncFn (/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/next/dist/build/tracer.js:3:435)
at build (/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/next/dist/build/index.js:1:7253)
at /Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/next/dist/cli/next-build.js:17:1246
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! next-video-chat@1.0.0 build: next build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the next-video-chat@1.0.0 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! /Users/bipin289/.npm/_logs/2021-02-19T06_43_56_482Z-debug.log

bipin289@Bipins-MBP next-video-chat %

log is reproduced below:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@6.14.11
3 info using node@v12.14.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle next-video-chat@1.0.0prebuild: next-video-chat@1.0.0
6 info lifecycle next-video-chat@1.0.0
build: next-video-chat@1.0.0
7 verbose lifecycle next-video-chat@1.0.0build: unsafe-perm in lifecycle true
8 verbose lifecycle next-video-chat@1.0.0
build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
9 verbose lifecycle next-video-chat@1.0.0build: CWD: /Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat
10 silly lifecycle next-video-chat@1.0.0
build: Args: [ '-c', 'next build' ]
11 silly lifecycle next-video-chat@1.0.0build: Returned: code: 1 signal: null
12 info lifecycle next-video-chat@1.0.0
build: Failed to exec build script
13 verbose stack Error: next-video-chat@1.0.0 build: next build
13 verbose stack Exit status 1
13 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:210:5)
13 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:210:5)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid next-video-chat@1.0.0
15 verbose cwd /Users/bipin289/Desktop/Working-Dir/articles-examples-nextjs-snippets/next-video-chat
16 verbose Darwin 20.3.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v12.14.0
19 verbose npm v6.14.11
20 error code ELIFECYCLE
21 error errno 1
22 error next-video-chat@1.0.0 build: next build
22 error Exit status 1
23 error Failed at the next-video-chat@1.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions