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

ServerBuilder: bundleDependencies "none" no longer works on Windows #14333

Closed
enten opened this issue May 3, 2019 · 2 comments
Closed

ServerBuilder: bundleDependencies "none" no longer works on Windows #14333

enten opened this issue May 3, 2019 · 2 comments
Assignees

Comments

@enten
Copy link

enten commented May 3, 2019

🐞 Bug report

Command (mark with an x)

- [ ] new
- [x] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

Yes, the previous version in which this bug was not present was: @angular/cli v8.0.0-beta.4 or @angular-devkit/build-angular v0.14.0-beta.4 (before commit 309b483).

Description

Commit 309b483 add changes on server builder model (packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/server.ts) which breaks option "bundleDependencies": "none" on Windows.

@@ -45,23 +36,15 @@ export function getServerConfig(wco: WebpackConfigOptions) {
  if (wco.buildOptions.bundleDependencies == 'none') {
    config.externals = [
      /^@angular/,
-     // tslint:disable-next-line:no-any
-     (_: any, request: any, callback: (error?: any, result?: any) => void) => {
+     (context: string, request: string, callback: (error?: null, result?: string) => void) => {
        // Absolute & Relative paths are not externals
        if (request.match(/^\.{0,2}\//)) {
          return callback();
        }

        try {
-         // Attempt to resolve the module via Node
-         const e = require.resolve(request);
-         if (/node_modules/.test(e)) {
-           // It's a node_module
-           callback(null, request);
-         } else {
-           // It's a system thing (.ie util, fs...)
-           callback();
-         }
+         require.resolve(request);
+         callback(null, request);
        } catch {
          // Node couldn't find it, so it must be user-aliased
          callback();

After these changes, main server entry path will be consider as external/node module (because require.resolve succeeded to resolve main server entry path).

Consequently:

  • bundle server succeded to build but main server entry isn't transpile ;
  • bundle server run crashes due to syntax error from typescript instructions.

Before these changes, Windows paths were consider as "system thing" because some path like C:\code\src\main.server.ts doesn't match ^\.{0,2}\/, can be resolve with require.resolve but doesn't contain node_modules.

Temporarily fix: we can use "bundleDependencies": "all" to ensure main server entry will be transpile but all server dependencies will be transpile (and bundle) too.

🔬 Minimal Reproduction

I haven't Internet access for the moment. As soon as I have Internet again: I will create a simple repository which reproduce the issue on Windows.

🔥 Exception or Error

$ ng run angular-test:server
$ node dist/server/main.js

C:\Users\enten_s\code\angular-test\src\main.server.ts:2
import 'zone.js/dist/zone-node';
       ^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected string
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)

🌍 Your Environment

Angular CLI: 8.0.0-beta.5
Node: 10.15.0
OS: win32 x64
Angular: 8.0.0-beta.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.14.0-beta.5
@angular-devkit/build-angular     0.14.0-beta.5
@angular-devkit/build-optimizer   0.14.0-beta.5
@angular-devkit/build-webpack     0.14.0-beta.5
@angular-devkit/core              8.0.0-beta.5
@angular-devkit/schematics        8.0.0-beta.5
@angular/cli                      8.0.0-beta.5
@ngtools/webpack                  8.0.0-beta.5
@schematics/angular               8.0.0-beta.5
@schematics/update                0.14.0-beta.5
rxjs                              6.4.0
typescript                        3.2.4
webpack                           4.29.6

Anything else relevant?

May there is another issue on Windows to resolve path to builder.

During writing this issue, I hit issue below but I don't have time to investigate more. May that it's related to another issue.

$ ng run angular-test:server

Could not find the implementation for builder @angular-devkit/build-angular:server
Error: Could not find the implementation for builder @angular-devkit/build-angular:server
    at WorkspaceNodeModulesArchitectHost.resolveBuilder (C:\Users\enten_s\code\angular-test\node_modules\@angular\cli\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:45:19)
    at RunCommand.runSingleTarget (C:\Users\enten_s\code\angular-test\node_modules\@angular\cli\models\architect-command.js:176:55)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
@alan-agius4 alan-agius4 added area: @angular-devkit/build-angular freq1: low Only reported by a handful of users who observe it rarely severity5: regression labels May 5, 2019
@ngbot ngbot bot added this to the needsTriage milestone May 5, 2019
@ngbot ngbot bot modified the milestones: needsTriage, Backlog May 5, 2019
@alan-agius4 alan-agius4 self-assigned this May 5, 2019
@alan-agius4 alan-agius4 modified the milestones: Backlog, 8.0 May 5, 2019
@ngbot ngbot bot modified the milestone: 8.0 May 5, 2019
@alan-agius4
Copy link
Collaborator

@enten, I have checked this and this should have been already solved in the recent RC versions.

https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/server.ts#L42

Kindly update to the latest RC versions and try again, If the problem persists kindly open a new issue, with the exact steps to reproduce it.

Thanks.

@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 Sep 9, 2019
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants