Node module in wrangler cannot be resolved

If I try to use http-errors is get back on building

✘ [ERROR] Could not resolve "http-errors"

      11 │ import {BadRequest, HttpError, MethodNotAllowed} from "http-errors";
         ╵                                                       ~~~~~~~~~~~~~

  You can mark the path "http-errors" as external to exclude it from the bundle, which will remove
  this error.

How to include the module properly?

What I did:

$ wrangler init req-test
 ⛅️ wrangler 2.0.12 (update available 2.0.15)
Using npm as package manager.
✨ Created req-test/wrangler.toml
Would you like to use git to manage this Worker? (y/n)
✨ Initialized git repository at req-test
No package.json found. Would you like to create one? (y/n)
✨ Created req-test/package.json
Would you like to use TypeScript? (y/n)
✨ Created req-test/tsconfig.json
Would you like to create a Worker at req-test/src/index.ts?
❯ Fetch handler
  Scheduled handler
✨ Created req-test/src/index.ts
npm WARN deprecated [email protected]: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.

added 60 packages, and audited 61 packages in 12s

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities
✨ Installed @cloudflare/workers-types and typescript into devDependencies

To start developing your Worker, run `cd req-test && npm start`
To publish your Worker to the Internet, run `npm run deploy`

$ cd req-test
$ npm install --save @types/http-errors

Than use this as src/index.ts :

import {BadRequest} from "http-errors";

export default {
  async fetch(
    request: Request,
    env: Env,
    ctx: ExecutionContext
  ): Promise<Response> {
    throw new BadRequest();
    return new Response("Hello World!");

Try starting the worker with

$ wrangler dev
 ⛅️ wrangler 2.0.12 (update available 2.0.15)
⬣ Listening at http://localhost:8787

✘ [ERROR] Could not resolve "http-errors"

      2 │ import {BadRequest} from "http-errors";
        ╵                          ~~~~~~~~~~~~~

  You can mark the path "http-errors" as external to exclude it from the bundle, which will remove
  this error.

✘ [ERROR] Build failed with 1 error:

  src/index.ts:2:25: ERROR: Could not resolve "http-errors"

If you think this is a bug then please create an issue at

You installed the types for http-errors not the package it’s self. Try npm install --save npm install http-errors

yep, stupid mistake. thks,

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.