Falldot / esbuild-dev-server

This plugin allows you to start a local server with hot reloading with Esbuild

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UnhandledPromiseRejectionWarning: Error: spawn /Users/user/template/node_modules/esbuild-dev-server/lib/../../esbuild-dev-server-darwin-x64/devserver EACCES

uns3t opened this issue · comments

commented

when i use this plugin, an error occurred

(node:63759) UnhandledPromiseRejectionWarning: Error: spawn /Users/react-esbuild-template/node_modules/esbuild-dev-server/lib/../../esbuild-dev-server-darwin-x64/devserver EACCES
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:467:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:63759) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:63759) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

and esbuild code is:

const esbuild = require('esbuild');
const { lessLoader } = require('esbuild-plugin-less');
const { htmlPlugin } = require('@craftamap/esbuild-plugin-html');
const esBuildDevServer = require("esbuild-dev-server")

const htmlPluginOptions = {
    files: [
        {
            entryPoints: [
                'src/app.tsx',
            ],
            filename: 'index.html',
            htmlTemplate: `
                <!DOCTYPE html>
                <html lang="en">
                <head>
                    <meta charset="UTF-8">
                    <meta name="viewport" content="width=device-width, initial-scale=1.0">
                    <title>React-esbuild-template</title>
                </head>
                <body>
                    <div id="root">
                    </div>
                </body>
                </html>
            `,
        },
    ]
}

const options = {
    entryPoints: ['src/app.tsx'],
    bundle: true,
    metafile: true, // needs to be set
    outdir: 'dist/', // needs to be set
    plugins: [
        htmlPlugin(htmlPluginOptions),
        lessLoader()
    ],
    loader: {
        '.ts': 'ts',
    },
}

esBuildDevServer.start(
        esbuild.build(options),
        {
            port:      "10002", // optional, default: 8080
            watchDir:  "src", // optional, default: "src"
            index:     "dist/index.html", // optional
            staticDir: "dist", // optional
            onBeforeRebuild: {}, // optional
            onAfterRebuild:  {}, // optional
        }
)

Hello. Thank you for contacting.

esbuild-dev-server calling rebuild repeatedly with the same options.
esbuild requires incremental: true property in options for this.
Read more: https://esbuild.github.io/api/#incremental

Add this property to the options and try again.

const options = {
    entryPoints: ['src/app.tsx'],
    bundle: true,
    metafile: true, // needs to be set
    outdir: 'dist/', // needs to be set
    incremental: true, // !important
    plugins: [
        htmlPlugin(htmlPluginOptions),
        lessLoader()
    ],
    loader: {
        '.ts': 'ts',
    },
}

I get the same error, and I made sure to use incremetal: true

esBuildDevServer.start(build({
  sourcemap: true,
  entryPoints: ['src/index.tsx'],
  bundle: true,
  outdir: 'build',
  platform: 'browser',
  minify: true,
  keepNames: true,
  target: 'es6',
  plugins: [
    lessLoader(),
  ],
  metafile: true,
  incremental: true,
}), {
  port:      '3000',
  watchDir:  'src',
  index:     'build/index.html',
  staticDir: 'build',
})

Please send the full text of your error.
What OS do you use? At what point do you get the error?

I get this error when I try running the server with the options above.
I use MacOS 11.6

(node:90358) UnhandledPromiseRejectionWarning: Error: spawn /Users/nikolamusikic/vt/vacationtracker/node_modules/esbuild-dev-server/lib/../../esbuild-dev-server-darwin-x64/devserver EACCES
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:467:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:90358) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:90358) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This happens, because the server binary is not set as executable. Same happens in Linux. Manually making it executable works.

Looking at the makefile and the paths in it, you probably build on Unix-type OS or WSL, so you probably just need a chmod here and there in the makefile.

Indeed - running chmod u+x node_modules/esbuild-dev-server-darwin-x64/devserver as a patch till fixed

For Ubuntu you can run
chmod u+x node_modules/esbuild-dev-server-linux-x64/devserver