Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expressjs static keyword #1279

Closed
PachoJGaviria opened this issue May 8, 2019 · 2 comments

Comments

@PachoJGaviria
Copy link

commented May 8, 2019

What version of standard?
12.0.1

What operating system, Node.js, and npm version?
macOS Mojave, 10.15.3, 6.9.0

What did you expect to happen?
I am using express(4.16.1) to serving static content and need import 'static' function
import express, { json, urlencoded, static } from 'express'

What actually happened?
But standard marketed the next error: Parsing error: The keyword 'static' is reserved (null)
How I can disable the rule null?

@LinusU

This comment has been minimized.

Copy link
Member

commented May 8, 2019

This is not actually a rule, but the parsing of the file is failing. I actually think that it isn't valid javascript to import a name named static.

e.g. this is what happens in Node.js 12:

$ cat a.mjs 
import { static } from './b.mjs'

$ cat b.mjs 
export function static () { return 1 }

$ node --experimental-modules a.mjs
(node:5927) ExperimentalWarning: The ESM module loader is experimental.
file:///private/tmp/hdjas/a.mjs:1
import { static } from './b.mjs'
         ^^^^^^

SyntaxError: Unexpected reserved word
    at Loader.moduleStrategy (internal/modules/esm/translators.js:48:18)
    at async link (internal/modules/esm/module_job.js:38:36)

That being said, Express.js is shipped as a common-js module, and not a ES module. Instead of trying to import multiple things from express, I would use express.json, express. urlencoded and express.static.

e.g.

import express from 'express'

// ...

app.use(express.static(/* ... */))

// ...
@PachoJGaviria

This comment has been minimized.

Copy link
Author

commented May 8, 2019

I agreed with you and I am going to change my code.
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.