Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Functions Entrypoint generates invalid Import on Windows #275

Closed
pschaeffer opened this issue Mar 16, 2024 · 13 comments · Fixed by #281
Closed

[Bug] Functions Entrypoint generates invalid Import on Windows #275

pschaeffer opened this issue Mar 16, 2024 · 13 comments · Fixed by #281
Labels
type: bug code to address defects in shipped code

Comments

@pschaeffer
Copy link

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
};

@pschaeffer pschaeffer added the type: bug code to address defects in shipped code label Mar 16, 2024
@Skn0tt
Copy link

Skn0tt commented Mar 26, 2024

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.

@Skn0tt Skn0tt transferred this issue from netlify/cli Mar 26, 2024
@Skn0tt Skn0tt changed the title Problem with Node? Netlify? Remix? [Bug] Functions Entrypoint generates invalid Import on Windows Mar 26, 2024
@pieh pieh closed this as completed in #281 Apr 3, 2024
@mrstork
Copy link
Contributor

mrstork commented Apr 3, 2024

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.

@pschaeffer
Copy link
Author

I think I am running the correct version of Remix. See the attached files.
<img width="776" alt="Captur
Capture2
e1" src="https://github.com/netlify/remix-compute/assets/3717450/3526f45e-23d3-4182-a6fd-df1b9aa93f78">

@mrstork
Copy link
Contributor

mrstork commented Apr 3, 2024

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
...

@pschaeffer
Copy link
Author

pschaeffer commented Apr 3, 2024 via email

@mrstork
Copy link
Contributor

mrstork commented Apr 4, 2024

You can specify "@netlify/remix-adapter": "^2.3.1", in your package.json and then try running npm install once again.

@pschaeffer
Copy link
Author

pschaeffer commented Apr 4, 2024 via email

@Skn0tt
Copy link

Skn0tt commented Apr 4, 2024

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.

@pschaeffer
Copy link
Author

Capture1

Capture2

0d"> 0-5346-4cbc-93d5-676dbcf5a95f"> 4b">

@pschaeffer
Copy link
Author

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.

@pschaeffer
Copy link
Author

pschaeffer commented Apr 4, 2024 via email

@mrstork
Copy link
Contributor

mrstork commented Apr 4, 2024

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 .

@pschaeffer
Copy link
Author

I am not sure where the actual problem in netlify3 is. Some files are attached.
Capture1
Capture2
I got those images after I entered a 'netlify dev' (without the quotes) command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants