Dev server serves stale JSON when functions use `import` statement for JSON
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- node.js, typescript
Hướng nghiên cứu
Tái hiện hành vi với netlify dev, netlify/functions/jsonTest.js, tệp my.json đã import và cấu hình [functions] node_bundler = "esbuild". So sánh phản hồi của curl trước và sau khi thay đổi my.json mà không khởi động lại server; được coi là hoàn tất khi function trả về JSON đã cập nhật trong khi dev server vẫn đang chạy.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- TypeScript
- Star
- 1.9k
- Fork
- 481
- Merge trung bình
- 1 ngày 14 giờ
- Pull request đã merge (30 ngày)
- 70
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của netlify/cli
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
netlify/cli#8645 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
db-status.test fails if the database is disabledCó thể đã có người làm @paulleephp đã nhận 5 ngày trước. Đang mởtype: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`client-ip` is not an IP address when `x-forwarded-for` holds a list or a portCó thể đã có người làm @Dev-next-gen đã nhận 25 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`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`)Có thể đã có người làm @bsplatt92 đã nhận 66 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area: command: deploy area: docs type: feature
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
netlify/cli#1984 · 19 bình luận · 3 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
bug skills
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
equinor/fusion-framework#5846 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Eyevinn/open-videocore#1256 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Frontend build fails with Frappe version-16: DataImport is no longer exported by @framework/uiĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Theme preset geist points at undefined --font-geistCó thể đã có người làm @claude đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày