I cannot seem to get my Netlify functions to work from the cli since I have re-installed my OS
When I try to access a function (to read a faunadb document) I get the error
http://localhost:5000/.netlify/functions/database-access 404 (Not Found)
( I am running on port 5000 because 8888 does not start)
Here is my function (db-acces.js )
const faunadb = require("faunadb");
const index_name = 'all_cars';
const collection_name = 'cars';
const query = faunadb.query;
// the project needs to be 'linked' to a netlify app for the cli version to work
const client = new faunadb.Client({
secret: process.env.FAUNADB_SECRET_TEST_CARS
});
exports.handler = async (event) => {
const context = JSON.parse(event.body);
const record = {data: context.record};
const key = context.key
var query_function
var record_key = query.Ref(query.Collection(collection_name), key)
try {
switch (context.access_type) {
case 'create':
query_function = query.Create(record_key, record)
break;
case 'read':
query_function = query.Get(record_key)
break;
case 'update':
query_function = query.Update(record_key, record)
break;
case 'delete':
query_function = query.Delete(record_key)
break;
case 'read-all':
query_function = query.Map(
query.Paginate(query.Match(query.Index(index_name))),
query.Lambda((x) => query.Get(x))
)
break;
}
var response = await client.query(query_function)
return {
statusCode: 200,
body: JSON.stringify(response.data),
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true,
},
};
} catch (error) {
return {
statusCode: 422,
body: JSON.stringify(error),
};
}
};
This is my Netlify site, which works as expected
https://netlify-svelte-fauna.netlify.app
CLI usually runs on :8888
. Are you sure yours is running on :5000
?
not running on 8888
but on 5000
This is my terminal output
(node:17722) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use node --trace-warnings ...
to show where the warning was created)
wasm streaming compile failed: TypeError: Failed to parse URL from /home/jeff/.nvm/versions/node/v18.7.0/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.wasm
falling back to ArrayBuffer instantiation
◈ Netlify Dev ◈
◈ Ignored site settings env var: FAUNADB_SECRET_TEST_CARS (defined in .env file)
◈ Injected .env file env var: FAUNADB_SECRET_TEST_CARS
◈ Ignored general context env var: LANG (defined in process)
◈ Ignored general context env var: LANGUAGE (defined in process)
◈ Loaded function database-access.
◈ Functions server is listening on 38097
◈ Starting Netlify Dev with Svelte
svelte-app@1.0.0 dev
rollup -c -w
rollup v2.73.0
bundles src/main.js → public/build/bundle.js…
LiveReload enabled on port 35732
created public/build/bundle.js in 835ms
svelte-app@1.0.0 start
sirv public --no-clear
Your application is ready~!
LOGS
⠴ Waiting for framework port 5000. This can be configured using the ‘targetPort’ property in the netlify.toml
This is the problem. Add:
[dev]
targetPort = 5000
to your netlify.toml
.
hrishikesh:
[dev]
targetPort = 5000
Thank you, I have tried that but the terminal output remains the same and the problem persists
I have reinstalled my os and have moved to nvm. Could that be an issue?
In that case, this must be the problem:
opened 08:35AM - 24 Jul 22 UTC
closed 08:54AM - 30 Sep 22 UTC
type: bug
waiting for upstream
### Describe the bug
Upgraded to latest 10.11.1, running `netlify dev`
It ju… st keeps hanging on "waiting for port forever"
⠋ Waiting for framework port 8080. This can be configured using the 'targetPort' property in the netlify.toml
No matter if I add the `targetPort` to netlify.toml or not, or also whhich port (tried 8080, 8888, 8081 etc)
```shell
valhalla-landers on main [?] via v18.6.0 on ☁️ took 45s
❯ netlify dev
(node:3821) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
wasm streaming compile failed: TypeError: Failed to parse URL from /usr/local/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.wasm
falling back to ArrayBuffer instantiation
◈ Netlify Dev ◈
◈ Ignored general context env var: LANG (defined in process)
◈ Ignored general context env var: LC_ALL (defined in process)
◈ Injected .env file env var: ELEVENTY_ENV
◈ Injected .env file env var: SITE_ID
◈ Injected .env file env var: BROWSER
◈ Injected .env file env var: WCT_API_KEY
◈ Injected .env file env var: UPSTASH_REDIS_REST_URL
◈ Injected .env file env var: UPSTASH_REDIS_REST_TOKEN
◈ Injected .env file env var: UPSTASH_CLOAKING_REDIS_REST_URL
◈ Injected .env file env var: UPSTASH_CLOAKING_REDIS_REST_TOKEN
◈ Injected .env file env var: IPDATA_API_KEY
◈ Loaded function create-redirects.
◈ Loaded function delete-redirects.
◈ Loaded function landers.
◈ Loaded function offers.
◈ Loaded function query.
◈ Functions server is listening on 53716
◈ Starting Netlify Dev with Eleventy
> valhalla-landers@1.0.0 dev
> run-p clean sass webpack:dev 11ty:dev
> valhalla-landers@1.0.0 clean
> rimraf dist/*
> valhalla-landers@1.0.0 sass
> sass resources/scss/main.scss dist/assets/css/main.css
> valhalla-landers@1.0.0 webpack:dev
> webpack --mode development --watch
> valhalla-landers@1.0.0 11ty:dev
> ELEVENTY_ENV=development npx @11ty/eleventy
1 asset
236 modules
webpack 5.69.1 compiled successfully in 1460 ms
[11ty] Writing dist/robots.txt from ./site/robots.njk
[11ty] Writing dist/9ffe3f93-8774-4e12-a1bf-540baec15ebb/index.html from ./site/index.njk
[11ty] Writing dist/70ffc2c1-feb1-47ea-ac72-63b2411ee09c/index.html from ./site/index.njk
[11ty] Writing dist/63e88395-9247-4b88-92c9-1ef649944149/index.html from ./site/index.njk
[11ty] Writing dist/pages/terms-of-use/index.html from ./site/pages/terms-of-use.md (njk)
[11ty] Writing dist/pages/contact/index.html from ./site/pages/contact.md (njk)
[11ty] Writing dist/pages/privacy-policy/index.html from ./site/pages/privacy-policy.md (njk)
[11ty] Writing dist/pages/legal-disclosure/index.html from ./site/pages/legal-disclosure.md (njk)
[11ty] Writing dist/404.html from ./site/404.md (njk)
[11ty] Writing dist/pages/about/index.html from ./site/pages/about.md (njk)
[11ty] Benchmark 798ms 54% 1× (Data) `./site/_data/valhalla.js`
[11ty] Copied 5 files / Wrote 10 files in 1.02 seconds (102.0ms each, v1.0.0)
⠙ Waiting for framework port 8080. This can be configured using the 'targetPort' property in the netlify.toml
```
My `package.json` scripts & deps:
```json
"scripts": {
"help": "npx @11ty/eleventy --help",
"clean": "rimraf dist/*",
"sass": "sass resources/scss/main.scss dist/assets/css/main.css",
"webpack:dev": "webpack --mode development --watch",
"webpack:prod": "webpack --mode production",
"11ty:dev": "ELEVENTY_ENV=development npx @11ty/eleventy --serve --watch",
"11ty:prod": "ELEVENTY_ENV=production npx @11ty/eleventy",
"dev": "run-p clean sass webpack:dev 11ty:dev",
"prod": "run-s sass 11ty:prod webpack:prod"
},
"dependencies": {
"@babel/runtime": "^7.17.2",
"@upstash/redis": "^1.0.3",
"alpinejs": "^3.9.1",
"axios": "^0.27.2",
"base64-url": "^2.3.3",
"ipdata": "^1.1.2",
"unfetch": "^4.2.0"
},
"devDependencies": {
"@11ty/eleventy": "^1.0.0",
"@11ty/eleventy-navigation": "^0.3.2",
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/preset-env": "^7.16.11",
"@babel/runtime-corejs3": "^7.17.2",
"babel-loader": "^8.2.3",
"clean-css": "^5.2.4",
"gorko": "^0.4.1",
"html-minifier": "^4.0.0",
"netlify-cli": "^10.11.1",
"node-html-parser": "^4.1.0",
"npm-run-all": "^4.1.5",
"postcss": "^8.3.5",
"purgecss": "^4.1.3",
"resolve-url-loader": "^4.0.0",
"rimraf": "^2.7.1",
"sass": "^1.49.9",
"webpack": "^5.69.1",
"webpack-cli": "^4.9.2"
}
```
### Steps to reproduce
Upgrade to latest version, use netlify.toml and package.json i posted here (I assume)
### Configuration
```toml
[build]
build = "/"
command = "npm run prod"
publish = "dist"
[dev]
command = "npm run dev"
framework = "eleventy"
publish = "dist"
[[headers]]
# Define which paths this specific [[headers]] block will cover.
for = "/*"
[headers.values]
Referrer-Policy = "no-referrer"
X-Frame-Options = "DENY"
X-Robots-Tag = "noindex"
X-XSS-Protection = "1; mode=block"
[functions]
# Directory with serverless functions, including background functions,
# to deploy. This is relative to the base directory if one has been set,
# or the root directory if a base hasn’t been set.
directory = ".netlify/functions"
```
### Environment
❯ npx envinfo --system --binaries --npmPackages netlify-cli --npmGlobalPackages netlify-cli
System:
OS: macOS 12.4
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 919.10 MB / 32.00 GB
Shell: 3.4.1 - /usr/local/bin/fish
Binaries:
Node: 18.6.0 - /usr/local/bin/node
npm: 8.13.2 - /usr/local/bin/npm
npmPackages:
netlify-cli: ^10.11.1 => 10.11.1
npmGlobalPackages:
netlify-cli: 10.11.1
Yes it was, see my response to
Hi @psionman
There are several threads on the CLI GitHub repository about this issue. Have you looked through them?