[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live)

[Help](/c/help/9)

# Issue compile static JS

128 views · 0 likes · 4 posts


Sodepr (@sodepr-deploy) · 2024-08-04

https://github.com/orgs/vercel/discussions/7508
https://github.com/orgs/vercel/discussions/3168


Dear fork,

I deploy a simple express.js to vercel but it does not work.

index.js

```
const express = require('express');

const app = express();


const path = require('path')
app.use(express.static(path.join(__dirname, '../static')));
app.get('/*', function(req, res){
  res.sendFile("index.html", {root: path.join(__dirname, '../static')});
});


app.get('/api', (req, res) => {
  res.send('Hello from Express.js!');
});


const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
  console.log('Press Ctrl+C to quit.');
});
```

In `static` folder, i have some JS files, the vercel build add some lines into the file ~~

```js
Object.defineProperty(exports, "__esModule", {
  value: true
});
```

I try to add `type: "module"` in package.json but all server will die.

Log:

```
Running "vercel build"
Vercel CLI 35.2.1
WARN! Due to `builds` existing in your configuration file, the Build and Development Settings defined in your Project Settings will not apply. Learn More: https://vercel.link/unused-build-settings
Installing dependencies...
up to date in 1s
12 packages are looking for funding
  run `npm fund` for details
Warning: Node.js functions are compiled from ESM to CommonJS. If this is not intended, add "type": "module" to your package.json file.
Compiling "index.js" from ESM to CommonJS...
Compiling "bootstrap.esm.min.js" from ESM to CommonJS...
Compiling "bootstrap.esm.js" from ESM to CommonJS...
Compiling "start.js" from ESM to CommonJS...
Build Completed in /vercel/output [1m]
Deploying outputs...
```

I want to compile only "index.js" from ESM to CommonJS. But vercel compile all file ~~

vercel.json

```json
{
  "version": 2,
  "cleanUrls": true,
  "framework": null,
  "installCommand": "npm install",
  "outputDirectory": ".",
  "public": false,
  "builds": [
    {
      "src": "/src/index.js",
      "use": "@vercel/node"
    }
  ],
  "rewrites": [{ "source": "/(.*)", "destination": "/src/index.js" }]
}
```

The same issue but no answer: https://github.com/orgs/vercel/discussions/3168
I think is a vercel bug?

Please help me ~~ there is no document for this issue.
Many thanks


Amy Egan (@amyegan) · 2024-08-05

Hi @sodepr-deploy. Have you tried the Express.js with Vercel guide? It has a walkthrough of recommended project setup and some tips about adapting Express to serverless environments.

https://vercel.com/guides/using-express-with-vercel


Sodepr (@sodepr-deploy) · 2024-08-05

Thank for you reply,

However, I cannot check, my account is paused because someone ddos my site ~~

![image|526x340](upload://mPcLAPP2XF8WfdYFCfRRLYzf5VK.jpeg)

Does vercel has any waf to protect api/website?


Amy Egan (@amyegan) · 2024-08-05

Sorry to hear your site is experiencing unexpectedly high usage. You can learn more about Vercel Firewall and [DDoS mitigation](https://vercel.com/docs/security/vercel-firewall#ddos-mitigation) here: 

https://vercel.com/docs/security/vercel-firewall