Skip to content

the example code for express is not working correctly #177

@Pusikas

Description

@Pusikas

When working with ESM, then using the following example code does not work anymore with v2.0.1:

import express from 'express';
import useragent from 'express-useragent';

const app = express();

app.use(useragent.express());

The default export does not have a function called express().

What does work is the following:

import express from 'express';
import * as useragent from 'express-useragent';

const app = express();

app.use(useragent.express());

You can also import the exported function itself, but that will collide with the express-import, so you have to rename:

import express from 'express';
import { express as mw } from 'express-useragent';

const app = express();

app.use(mw());

You may want to update your documentation here. The example still works for CommonJS code using require().

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