[Bug] Functions Entrypoint generates invalid Import on Windows
Closed this issue · 13 comments
Describe the bug
I am getting an error when I try to run my application. I am not sure if this is a node error or Netlify error or a Remix error. See below. I get the error shown below. What does node:internal mean? I have no idea.
Function remix-server has returned an error: Invalid module "...uildserverserver.js" is not a valid package name imported from C:\Users\Peter\Documents\Visual_Studio_Code\Projects\WebApplication5\WebApplication5\my-remix-udemy-section3-netlify2.netlify\functions-serve.unzipped\remix-server\remix-server.mjs
TypeError: Invalid module "...uildserverserver.js" is not a valid package name imported from C:\Users\Peter\Documents\Visual_Studio_Code\Projects\WebApplication5\WebApplication5\my-remix-udemy-section3-netlify2.netlify\functions-serve.unzipped\remix-server\remix-server.mjs
at new NodeError (node:internal/errors:406:5)
at parsePackageName (node:internal/modules/esm/resolve:718:11)
at packageResolve (node:internal/modules/esm/resolve:740:5)
at moduleResolve (node:internal/modules/esm/resolve:838:20)
at defaultResolve (node:internal/modules/esm/resolve:1043:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:38)
at ModuleWrap. (node:internal/modules/esm/module_job:85:39)
at link (node:internal/modules/esm/module_job:84:36)
Response with status 500 in 446 ms.
Steps to reproduce
Execute 'netlify serve'. For some reason 'netlify dev' works.
Configuration
[build]
command = "npx prisma generate && npm run build"
publish = "build/client"
[dev]
command = "npm run dev"
framework = "vite"
Set immutable caching for static files, because they have fingerprinted filenames
[[headers]]
for = "/build/*"
[headers.values]
"Cache-Control" = "public, max-age=31560000, immutable"
Environment
Quite standard. The code below is being stored in .netlify/functions-server/.unzipped/remix-server/remix-server.mjs
import {createRequire as ___nfyCreateRequire} from "module";
import {fileURLToPath as ___nfyFileURLToPath} from "url";
import {dirname as ___nfyPathDirname} from "path";
let __filename=___nfyFileURLToPath(import.meta.url);
let __dirname=___nfyPathDirname(___nfyFileURLToPath(import.meta.url));
let require=___nfyCreateRequire(import.meta.url);
// .netlify/functions-internal/remix-server.mjs
import { default as default2 } from "....\buildserverserver.js";
var config = {
name: "Remix server handler",
generator: "@netlify/remix-adapter@2.3.0",
path: "/*",
preferStatic: true
};
export {
config,
default2 as default
};
The problem seems to be that import { default as default2 } from "....\buildserverserver.js";
should be import { default as default2 } from "../../build/server/server.js";
instead. This seems to be a windows-specific issue.
This code piece is generated by https://github.com/netlify/remix-compute/blob/0bfe42de2205537528fd6c72d1f95a81798e09b7/packages/remix-adapter/src/plugin.ts#L18C32-L18C38, and it seems that we're generating a Windows path where we should be generating a Unix path instead. I'll move this issue over to that repository.
This has been resolved in #281.
Please ensure you are using @netlify/remix-adapter@2.3.1
which includes the fix. Running npm install
in the project directory should automatically install the latest version for you.
I think I am running the correct version of Remix. See the attached files.
<img width="776" alt="Captur
e1" src="https://github.com/netlify/remix-compute/assets/3717450/3526f45e-23d3-4182-a6fd-df1b9aa93f78">
We released a new version of remix-adapter
today, you'll have to update your code to use it and try again. The project pschaeffer/my-remix-udemy-section3-netlify3 is still using v2.3.0
.
One way to verify what version you are using is to run npm list
in the root of the project and ensuring that the following shows up:
...
├── @netlify/remix-adapter@2.3.1
...
You can specify "@netlify/remix-adapter": "^2.3.1",
in your package.json
and then try running npm install
once again.
Peter, it looks like the screenshots weren't properly attached to your reply. Could you try posting them again within the GitHub UI? The reply-via-email feature seems to be lacking in formatting & attachments.
You should have all the screenshots at this point. I updated my-remix-udemy-section3-netlify3 with the newest code. Note that this repository does not include the node_folders folder. It was too large for git.
The second screenshot doesn't look to have uploaded properly, however based on the first screenshot alone this doesn't look to be related to the original issue you posted about (i.e. TypeError: Invalid module "...uildserverserver.js" is not a valid package name imported from ...
).
When I download your repository my-remix-udemy-section3-netlify3
I get the error TypeError: Cannot convert object to primitive value
. I get this error when I run remix vite:dev
as well as when I run netlify serve
, which indicates to me this in not an issue with the remix-adapter
but rather an issue with how your project has been configured.
If you are certain your project is configured correctly and the issue is elsewhere, then we need your help! Please open up a new issue in the appropriate repository (e.g. remix, remix-adapter, netlify-cli, node), and please include a minimal reproducible example to help the community zero in on the root cause of the problem. Here is a helpful resource describing how to create minimal reproducible examples .