Dev server serves stale JSON when functions use `import` statement for JSON
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- node.js, typescript
Línea de trabajo
Reproduce el comportamiento con netlify dev, netlify/functions/jsonTest.js, el archivo my.json importado y la configuración [functions] node_bundler = "esbuild". Compara la respuesta de curl antes y después de cambiar my.json sin reiniciar el servidor; se considera terminado cuando la función devuelve el JSON actualizado mientras el servidor de desarrollo sigue ejecutándose.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
When a Netlify function imports a JSON file with import myJson from './my.json', it will only ever return the contents of ./my.json as they were when the dev server was started, even after ./my.json is modified while the server is running.
While import statements only run once when executing the file, Netlify functions are AWS Lambdas which are expected to be executed from scratch and thus run the import statement with every execution. But netlify dev doesn't behave this way, only reloading the function's code when the actual code is changed.
This is an issue in development: I'm working on translating an application, and the translations go into a JSON file. A netlify function returns the corresponding language's JSON which is loaded with an import statement. The result is that as I add new strings to the JSON file, the function only ever returns the JSON file as it was when the dev server was started. The only way is to kill and restart the dev server.
Steps to reproduce
- Create a JSON file with these contents:
{}at./my.json - Create a Netlify function with these contents:
// netlify/functions/jsonTest.js
import myJson from './my.json'
const handler = event => {
return {
headers: { "Content-Type": "application/json" },
statusCode: 200,
body: JSON.stringify(myJson)
}
}
export { handler }
- Start the dev server with
netlify dev curl localhost:8888/jsonTest- Get
{}as the response - Without stopping the dev server, overwrite
./my.jsonwith these contents:{"netlify":"rocks"} curl localhost:8888/jsonTest- Get
{}as the response, instead of the current contents for./my.json - Kill the dev server
- Start the dev server again with
netlify dev curl localhost:8888/jsonTest- Get
{"netlify":"rocks"}as the response
Note that every once in a while, it will actually reload the function and re-run the import statement so you'll get the updated contents for the JSON file. But most of the time, it doesn't and serves stale contents
Configuration
[dev]
autoLaunch = false
[build]
command = "astro build"
functins = "netlify/functions"
publish = "dist"
[functions]
node_bundler = "esbuild"
Environment
System:
OS: Linux 5.15 Linux Mint 20.3 (Una)
CPU: (8) x64 Intel(R) Xeon(R) E-2134 CPU @ 3.50GHz
Memory: 12.83 GB / 46.93 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 18.15.0 - ~/.nvm/versions/node/v18.15.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v18.15.0/bin/yarn
npm: 9.8.1 - ~/.nvm/versions/node/v18.15.0/bin/npm
pnpm: 8.9.2 - ~/.nvm/versions/node/v18.15.0/bin/pnpm
npmPackages:
netlify-cli: ^16.8.0 => 16.8.0
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.9k
- Forks
- 480
- Merge medio
- 1 d 14 h
- PR fusionados (30 d)
- 70
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de netlify/cli
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
netlify/cli#8645 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
db-status.test fails if the database is disabledPosiblemente ocupada @paulleephp la tomó hace 3 días. Abiertotype: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
`client-ip` is not an IP address when `x-forwarded-for` holds a list or a portPosiblemente ocupada @Dev-next-gen la tomó hace 24 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
`netlify dev` with `--cwd` from outside the project: every function 500s with "module is not defined in ES module scope" (`detectZisiBuilder` passes a string to `readPackageUp`)Posiblemente ocupada @bsplatt92 la tomó hace 65 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
area: command: deploy area: docs type: feature
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
netlify/cli#1984 · 19 comentarios · 3 reacciones ·
Los mantenedores suelen responder en 1 día
Todos los issues de netlify/cli
Issues similares
-
agent/scanner help wanted hive/claimed-by-scanner kind/bug stage/020-claimed
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
hivecommons/rationguard#315 ·
Los mantenedores suelen responder en 1 día
-
agent-ready area: ui-sdk priority: p3 type: chore
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
schlessera/brain-kit#2534 ·
Los mantenedores suelen responder en 1 día
-
bug lane:gh-5
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
LLM-4-People/bridlewise-testing#122 ·
Los mantenedores suelen responder en 1 día
-
bug priority: P2
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
enhancement priority:low ready-for-dev
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Los mantenedores suelen responder en 1 día