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

Fresh project on Windows fails if not used with WSL #688

Closed
DmitryEfimenko opened this issue Oct 4, 2023 · 10 comments · Fixed by #915
Closed

Fresh project on Windows fails if not used with WSL #688

DmitryEfimenko opened this issue Oct 4, 2023 · 10 comments · Fixed by #915
Labels
bug Something isn't working

Comments

@DmitryEfimenko
Copy link

Please provide the environment you discovered this bug in.

Windows

Which area/package is the issue in?

create-analog

Description

I'm on a Windows as well. Tried starting a fresh project following "Getting Started" docs. Immediately received an error when attempted to start the project:

Please provide the exception or error you saw

$ npm run build

> app@0.0.0 build
> ng build

vite v4.4.10 building for production...
✓ 341 modules transformed.
dist/client/index.html                             1.75 kB │ gzip:  1.31 kB
dist/client/assets/index-05bc7378.css              5.95 kB │ gzip:  1.86 kB
dist/client/assets/index.page-af7a8736.js          1.31 kB │ gzip:  0.72 kB
dist/client/assets/analogjs-content-a8651e95.js  138.45 kB │ gzip: 44.83 kB
dist/client/assets/index-29aeeebf.js             260.23 kB │ gzip: 82.55 kB
Building SSR application...
✓ built in 5.95s
vite v4.4.10 building SSR bundle for production...
✓ 31 modules transformed.
dist/ssr/assets/index.page-60cc8828.mjs            2.48 kB
dist/ssr/assets/analogjs-content-72cce11b.mjs     18.53 kB
dist/ssr/assets/xhr2-516fb8e9.mjs                 36.46 kB
dist/ssr/main.server.mjs                       1,305.53 kB
✓ built in 5.00s
Prerendering static pages...
[nitro] [request error] [unhandled] Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:' 
  at new NodeError (node:internal/errors:393:5)  
  at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1026:11)  
  at defaultResolve (node:internal/modules/esm/resolve:1106:3)  
  at nextResolve (node:internal/modules/esm/loader:163:28)  
  at ESMLoader.resolve (node:internal/modules/esm/loader:837:30)  
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)  
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)  
  at link (node:internal/modules/esm/module_job:75:36)
Building Server...


The '@analogjs/platform' server has been successfully built.

Dima@DESKTOP-EMG7TP2 MINGW64 /c/Source/nashdvor/nashdvor-app (main)
$ npm start

> app@0.0.0 start
> npm run dev


> app@0.0.0 dev
> ng serve



The server endpoints are accessible under the "/api" path.
  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
8:17:15 PM [vite] Error when evaluating SSR module /node_modules/@angular/core/fesm2022/core.mjs: failed to import "rxjs"
|- TypeError: Method Promise.prototype.then called on incompatible receiver [object Object]      
    at ZoneAwarePromise.then (<anonymous>)
    at node:internal/per_context/primordials:440:35
    at new Promise (<anonymous>)
    at new SafePromise (node:internal/per_context/primordials:408:29)
    at node:internal/per_context/primordials:440:9
    at Array.map (<anonymous>)
    at arrayToSafePromiseIterable (node:internal/per_context/primordials:437:5)
    at node:internal/per_context/primordials:453:21
    at new Promise (<anonymous>)
    at primordials.SafePromiseAll (node:internal/per_context/primordials:452:3)

8:17:15 PM [vite] Error when evaluating SSR module ~analog/entry-server: failed to import "/node_modules/@angular/core/fesm2022/core.mjs"
|- TypeError: Method Promise.prototype.then called on incompatible receiver [object Object]      
    at ZoneAwarePromise.then (<anonymous>)
    at node:internal/per_context/primordials:440:35
    at new Promise (<anonymous>)
    at new SafePromise (node:internal/per_context/primordials:408:29)
    at node:internal/per_context/primordials:440:9
    at Array.map (<anonymous>)
    at arrayToSafePromiseIterable (node:internal/per_context/primordials:437:5)
    at node:internal/per_context/primordials:453:21
    at new Promise (<anonymous>)
    at primordials.SafePromiseAll (node:internal/per_context/primordials:452:3)

Unhandled Promise rejection: Method Promise.prototype.then called on incompatible receiver [object Object] ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Method Promise.prototype.then called on incompatible receiver [object Object]
    at ZoneAwarePromise.then (<anonymous>)
    at node:internal/per_context/primordials:440:35
    at new Promise (<anonymous>)
    at new SafePromise (node:internal/per_context/primordials:408:29)
    at node:internal/per_context/primordials:440:9
    at Array.map (<anonymous>)
    at arrayToSafePromiseIterable (node:internal/per_context/primordials:437:5)
    at node:internal/per_context/primordials:453:21
    at new Promise (<anonymous>)
    at primordials.SafePromiseAll (node:internal/per_context/primordials:452:3) TypeError: Method Promise.prototype.then called on incompatible receiver [object Object]
    at ZoneAwarePromise.then (<anonymous>)
    at node:internal/per_context/primordials:440:35
    at new Promise (<anonymous>)
    at new SafePromise (node:internal/per_context/primordials:408:29)
    at node:internal/per_context/primordials:440:9
    at Array.map (<anonymous>)
    at arrayToSafePromiseIterable (node:internal/per_context/primordials:437:5)
    at node:internal/per_context/primordials:453:21
    at new Promise (<anonymous>)
    at primordials.SafePromiseAll (node:internal/per_context/primordials:452:3)


### Other information

_No response_

### I would be willing to submit a PR to fix this issue

- [ ] Yes
- [ ] No
@DmitryEfimenko DmitryEfimenko added the bug Something isn't working label Oct 4, 2023
@brandonroberts
Copy link
Member

Thanks @DmitryEfimenko. Analog has been confirmed to work on Windows using WSL. You must also be on Node >= 18.13.0

@DmitryEfimenko
Copy link
Author

confirming that it works from WSL.

Although I'd, of course still prefer to have native Windows support.

@brandonroberts
Copy link
Member

Of course. If you'd like to look into the path issue that would help, as I don't have a Windows machine

@brandonroberts brandonroberts changed the title Fresh project on Windows fails Fresh project on Windows fails if not used with WSL Oct 5, 2023
@fen89
Copy link

fen89 commented Dec 6, 2023

I can confirm that a build on a newly created project on windows fails:

Prerendering static pages...
[nitro] [request error] [unhandled] Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
  at new NodeError (node:internal/errors:406:5)
  at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:216:11)
  at defaultLoad (node:internal/modules/esm/load:118:3)
  at ModuleLoader.load (node:internal/modules/esm/loader:396:13)
  at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:56)
  at new ModuleJob (node:internal/modules/esm/module_job:65:26)
  at #createModuleJob (node:internal/modules/esm/loader:290:17)
  at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:248:34)
  at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:229:17)
  at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:21)
[nitro] [request error] [unhandled] Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
  at new NodeError (node:internal/errors:406:5)
  at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:216:11)
  at defaultLoad (node:internal/modules/esm/load:118:3)
  at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:56)
  at new ModuleJob (node:internal/modules/esm/module_job:65:26)
  at #createModuleJob (node:internal/modules/esm/loader:290:17)
  at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:248:34)
  at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:229:17)
  at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:21)
[nitro] [request error] [unhandled] Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
  at new NodeError (node:internal/errors:406:5)
  at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:216:11)
  at defaultLoad (node:internal/modules/esm/load:118:3)
  at ModuleLoader.load (node:internal/modules/esm/loader:396:13)
  at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:56)
  at new ModuleJob (node:internal/modules/esm/module_job:65:26)
  at #createModuleJob (node:internal/modules/esm/loader:290:17)
  at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:248:34)
  at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:229:17)
  at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:21)
[nitro] [request error] [unhandled] Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
  at new NodeError (node:internal/errors:406:5)
  at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:216:11)
  at defaultLoad (node:internal/modules/esm/load:118:3)
  at ModuleLoader.load (node:internal/modules/esm/loader:396:13)
  at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:56)
  at new ModuleJob (node:internal/modules/esm/module_job:65:26)
  at #createModuleJob (node:internal/modules/esm/loader:290:17)
  at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:248:34)
  at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:229:17)
  at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:21)


The '@analogjs/platform' server has been successfully built.

The static pages are not generated. I am still trying to figure out how I can handle this.

  • Tested with node v20.9.0

@konuch
Copy link

konuch commented Feb 3, 2024

I can confirm, that native support is still an issue on Windows. Resolving this issue migth speed up the adoption of analogjs.

@brandonroberts
Copy link
Member

Can someone try setting the workspaceRoot in the analog plugin in the vite.config.ts to see if that resolves the issue? From what I understand, Windows can't use an absolute path there, which is what we use if none is provided.

analog({
  workspaceRoot: '.'
})

@lo6ic
Copy link

lo6ic commented Feb 19, 2024

Hello Brandon. I've been dealing with this issue for a couple weeks now. I added the 'workspaceRoot' idea you had and I can confirm, it does not fix the issue. I also tried replacing the '.' value with 'file://' but that lead to a no such file or directory error. I'll keep digging on this issue but may need to do the workaround of installing WSL.

@fen89
Copy link

fen89 commented Feb 20, 2024

Can someone try setting the workspaceRoot in the analog plugin in the vite.config.ts to see if that resolves the issue? From what I understand, Windows can't use an absolute path there, which is what we use if none is provided.

analog({
  workspaceRoot: '.'
})

I tried the above, still the same issue.

@angelfraga
Copy link
Contributor

angelfraga commented Feb 29, 2024

Hi, I am also using windows and I got similar issues. So WSL is the workaround for me as well.

In my case (windows 11, latest analog, node 20.10.0 & angular 17), the same error occurs in nitropack when running the prerender of SSG.

It seems to be not only a problem of analog framework, actually here are related issues in nitro repo

nitrojs/nitro#718
nitrojs/nitro#836

In addition that problem is located in the prerenderer.mjs . If you look for import renderer$1 from 'C: in the dist folder (at least in my case is just that file) , all the others are imports such as import renderer$1 from 'file//C: . So I guess the problem is the prerender generation in nitro side.

UPDATE

After debuging a littel bit I got it working under windows by prefixing file:// for that import.

Adding to node_modules\.pnpm\nitropack@2.8.1\node_modules\nitropack\dist\shared\nitro.4ea992bc.mjs in the line 546

async resolveId(originalId, importer, options) {
  // here
  if(originalId.indexOf('main.server') > -1) {
     originalId = "file://"+originalId
  }

Then all static html files are generated properly. So I will give another try to debug in the call chain to figure out if is a real issue in nitro or a wrong configuration in analog.

@fen89
Copy link

fen89 commented Mar 1, 2024

Hi, I am also using windows and I got similar issues. So WSL is the workaround for me as well.

In my case (windows 11, latest analog, node 20.10.0 & angular 17), the same error occurs in nitropack when running the prerender of SSG.

It seems to be not only a problem of analog framework, actually here are related issues in nitro repo

unjs/nitro#718 unjs/nitro#836

In addition that problem is located in the prerenderer.mjs . If you look for import renderer$1 from 'C: in the dist folder (at least in my case is just that file) , all the others are imports such as import renderer$1 from 'file//C: . So I guess the problem is the prerender generation in nitro side.

UPDATE

After debuging a littel bit I got it working under windows by prefixing file:// for that import.

Adding to node_modules\.pnpm\nitropack@2.8.1\node_modules\nitropack\dist\shared\nitro.4ea992bc.mjs in the line 546

async resolveId(originalId, importer, options) {
  // here
  if(originalId.indexOf('main.server') > -1) {
     originalId = "file://"+originalId
  }

Then all static html files are generated properly. So I will give another try to debug in the call chain to figure out if is a real issue in nitro or a wrong configuration in analog.

@angelfraga The thing is, that I am running multiple nuxtjs projects (which is built around nitro) on my windows machine without having any path problems ever. So most likely the problem lies be somewhere in between analog and nitro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants