# Netlify dev failing with "Cannot use import statement outside a module"

I’m new to your platform, but I’ve been using vercel for awhile, and haven’t had any problems deploying on their site. I’m unable to get my functions to work. Here’s the output I’m getting when I run “netlify dev”:

(node:8296) 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: fetch failed
falling back to ArrayBuffer instantiation
◈ Netlify Dev ◈
◈ Injected .env file env var: MONGODB_URI
◈ Functions server is listening on 56922
◈ Starting Netlify Dev with Svelte

> eprodify@1.0.0 dev
> rollup -c -w

rollup v2.77.2
bundles src/app.js → public/build/bundle.js...
created public/build/bundle.js in 5.2s

> eprodify@1.0.0 start
> sirv public --no-clear

- Local:      http://localhost:8080
- Network:    Add --host to expose

LOGS

[17:56:17] 200 ─ 3.69ms ─ /
[17:56:17] 200 ─ 5.38ms ─ /build/bundle.css?livereload=1659574576491
[17:56:17] 200 ─ 2.19ms ─ /build/bundle.css
[17:56:17] 200 ─ 10.62ms ─ /build/bundle.js
[17:56:17] 200 ─ 4.94ms ─ /build/bundle.js.map
[17:56:17] 200 ─ 0.60ms ─ /favicon.png
bundles src/app.js → public/build/bundle.js...
created public/build/bundle.js in 1.7s
[17:56:26] 200 ─ 0.78ms ─ /
[17:56:26] 200 ─ 1.71ms ─ /build/bundle.css
[17:56:26] 200 ─ 8.63ms ─ /build/bundle.js
- Waiting for framework port 5000. This can be configured using the 'targetPort' property in the netlify.tomlRequest from ::1: OPTIONS /.netlify/functions/auth
{"level":"error","message":"End - Error:"}
Response with status 500 in 21 ms.
[17:56:26] 200 ─ 4.90ms ─ /build/bundle.js.map
[17:56:26] 200 ─ 0.56ms ─ /favicon.png
| Waiting for framework port 5000. This can be configured using the 'targetPort' property in the netlify.toml

So there are several issues here:

1. What is the noise about “fetch”?
2. When I run my site on :8080 and call my functions at :3000 I get the server 500 error, as indicated with the error messages. I don’t understand why it’s failing. (Note: these same functions work fine on vercel.)
3. What is it waiting for on port 5000? Which eventually times out and fails/exits. This is a Svelte site, and it does successfully build it and serves from 8080. So what is supposed to be on 5000?

Thanks for any help here.

Also, here’s my config file:

[build]
command = "npm run build"
functions = "/api"
publish = "public"

## Uncomment to use this redirect for Single Page Applications like create-react-app.
## Not needed for static site generators.
#[[redirects]]
#  from = "/*"
#  to = "/index.html"
#  status = 200

## (optional) Settings for Netlify Dev
## https://github.com/netlify/cli/blob/main/docs/netlify-dev.md#project-detection
#[dev]
#  command = "yarn start" # Command to start your dev server
#  port = 3000 # Port that the dev server will be listening on
#  publish = "dist" # Folder with the static content for _redirect file

[dev]
#port = 8888
#targetPort=
functionsPort=3000
command = "npm run dev"

Node Fetch switched to ESM-only since their version 3 release. ESM in Netlify Functions can be used with:

Why would you do that? Functions and Site should run on the same port so you can directly call them like /.netlify/functions/something instead of having to specify a port, which would most likely cause issues in production.

It mentions that here:

It’s waiting for your framework. If your framework is using a different port, feel free to change add the following to your netlify.toml:

[dev]
targetPort = ####

You should not need this. Let the CLI run Functions on any port, they should be usable on :8888 (along with your site).

So it’s still not clear:

1. Is node fetch failing here, or is this just a warning?

2. “Why would I do that”? I’m talking about running in development mode on localhost, so I need to use ports. My site is at :8080, because that’s how it’s configured in the svelte project. I’m specifically specifying “functionsPort=3000” in the config file.

3. I don’t understand “waiting for your framework”. This is a Svelte project. What framework are you talking about? Furthermore, after awhile “netlify dev” fails this wait and quits. How do you tell it to not do that?

Now I’m seemingly getting to my functions?, but I get this error:

{“level”:“error”,“message”:“End - Error:”}

What does this mean?

Thanks for any help here.

I’ve explained that before, but here you go again: