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

Error When Running ng serve Since Version 18.1.0-next.1 : Pre-transform error: Failed to load url ./main.server.mjs (resolved id: ./main.server.mjs). Does the file exist #27907

Closed
1 task done
naveedahmed1 opened this issue Jun 22, 2024 · 6 comments · Fixed by #27910
Assignees

Comments

@naveedahmed1
Copy link

naveedahmed1 commented Jun 22, 2024

Command

serve

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Since version 18.1.0-next.1 I am receiving the below error when running ng serve, whereas ng serve --configuration production seems to be working fine.

9:37:49 pm [vite] Pre-transform error: Failed to load url ./main.server.mjs (resolved id: ./main.server.mjs). Does the file exist?

Below is my package.json file:

"dependencies": {
    "@angular/animations": "18.1.0-next.3",
    "@angular/cdk": "18.1.0-next.3",
    "@angular/common": "18.1.0-next.3",
    "@angular/compiler": "18.1.0-next.3",
    "@angular/core": "18.1.0-next.3",
    "@angular/fire": "18.0.1",
    "@angular/forms": "18.1.0-next.3",
    "@angular/google-maps": "18.1.0-next.3",
    "@angular/material": "18.1.0-next.3",
    "@angular/platform-browser": "18.1.0-next.3",
    "@angular/platform-browser-dynamic": "18.1.0-next.3",
    "@angular/platform-server": "18.1.0-next.3",
    "@angular/pwa": "18.1.0-next.3",
    "@angular/router": "18.1.0-next.3",
    "@angular/service-worker": "18.1.0-next.3",
    "@fingerprintjs/fingerprintjs": "3.4.0",
    "@ngx-pwa/local-storage": "18.0.0",
    "@swimlane/ngx-charts": "20.5.0",
    "@zootools/email-spell-checker": "1.12.0",
    "d3-shape": "1.3.7",
    "dayjs": "^1.11.9",
    "easy-speech": "^2.3.1",
    "event-source-polyfill": "1.0.31",
    "file-saver": "2.0.5",
    "firebase": "10.12.2",
    "ng-recaptcha": "13.2.1",
    "ng2-adsense": "14.0.0",
    "ng2-ckeditor": "1.3.7",
    "ngx-img-cropper": "14.0.1",
    "ngx-infinite-scroll": "18.0.0",
    "ngx-stripe": "18.1.0",
    "rxjs": "~7.8.0",
    "screenfull": "5.0.2",
    "tslib": "^2.3.0",
    "zone.js": "~0.14.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "18.1.0-next.3",
    "@angular/cli": "18.1.0-next.3",
    "@angular/compiler-cli": "18.1.0-next.3",
    "@cloudflare/workers-types": "4.20240405.0",
    "@miniflare/tre": "3.0.0-next.14",
    "@types/express": "^4.17.17",
    "@types/jasmine": "~5.1.0",
    "@types/node": "^18.18.0",
    "@types/webappsec-credential-management": "^0.6.5",
    "concat": "3.0.0",
    "html-minifier-terser": "^5.1.1",
    "jasmine-core": "~5.1.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.1.0",
    "typescript": "~5.4.5",
    "wrangler": "^3.48.0"
  }

Minimal Reproduction

@alan-agius4 you can reproduce it in the private repo I have shared earlier.

Exception or Error

`9:37:49 pm [vite] Pre-transform error: Failed to load url ./main.server.mjs (resolved id: ./main.server.mjs). Does the file exist?`

Your Environment

Angular CLI: 18.1.0-next.3
Node: 20.12.2
Package Manager: npm 10.6.0
OS: win32 x64

Angular: 18.1.0-next.3
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, google-maps, material, platform-browser
... platform-browser-dynamic, platform-server, pwa, router
... service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1801.0-next.3
@angular-devkit/build-angular   18.1.0-next.3
@angular-devkit/core            18.0.2
@angular-devkit/schematics      18.0.2
@angular/fire                   18.0.1
@schematics/angular             18.0.2
rxjs                            7.8.1
typescript                      5.4.5
zone.js                         0.14.4

Anything else relevant?

No response

@alan-agius4 alan-agius4 self-assigned this Jun 23, 2024
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Jun 23, 2024
…ling

Replacing the paths to ESM in Vite can cause prebundling to fail in some cases, resulting in errors similar to the following:

```
12:55:12 PM [vite] Error when evaluating SSR module /chunk-CHB4JJIP.mjs:
|- TypeError: Cannot read properties of undefined (reading 'Subject')
    at eval (//src/app/shared/snackbar/snackbar.service.ts:2:25)
    at async instantiateModule (file:////node_modules/vite/dist/node/chunks/dep-BcXSligG.js:53408:5)

12:55:12 PM [vite] Error when evaluating SSR module /chunk-GQZ5BKXC.mjs:
|- TypeError: Cannot read properties of undefined (reading 'Subject')
    at eval (//src/app/shared/snackbar/snackbar.service.ts:2:25)
    at async instantiateModule (file:////node_modules/vite/dist/node/chunks/dep-BcXSligG.js:53408:5)
```

Closes: angular#27907
alan-agius4 added a commit that referenced this issue Jun 24, 2024
…ling

Replacing the paths to ESM in Vite can cause prebundling to fail in some cases, resulting in errors similar to the following:

```
12:55:12 PM [vite] Error when evaluating SSR module /chunk-CHB4JJIP.mjs:
|- TypeError: Cannot read properties of undefined (reading 'Subject')
    at eval (//src/app/shared/snackbar/snackbar.service.ts:2:25)
    at async instantiateModule (file:////node_modules/vite/dist/node/chunks/dep-BcXSligG.js:53408:5)

12:55:12 PM [vite] Error when evaluating SSR module /chunk-GQZ5BKXC.mjs:
|- TypeError: Cannot read properties of undefined (reading 'Subject')
    at eval (//src/app/shared/snackbar/snackbar.service.ts:2:25)
    at async instantiateModule (file:////node_modules/vite/dist/node/chunks/dep-BcXSligG.js:53408:5)
```

Closes: #27907
@naveedahmed1
Copy link
Author

naveedahmed1 commented Jun 26, 2024

@alan-agius4 is it fixed it 18.1.0-rc.0 ? I tried this version and still face the same error [vite] Pre-transform error: Failed to load url ./main.server.mjs (resolved id: ./main.server.mjs). Does the file exist?

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jun 26, 2024

@naveedahmed1, yes and I am no longer able to replicate.

@naveedahmed1
Copy link
Author

Have you tried it on Windows machine?

@alan-agius4
Copy link
Collaborator

I was able to replicate the issue on Windows and have submitted a pull request to address it: #27946

@naveedahmed1
Copy link
Author

Thank you so much Alan!

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants