Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

webpack does not work with latest @ngtools/webpack 6.1.0-rc.1 #607

Closed
manoldonev opened this issue Jul 10, 2018 · 18 comments · Fixed by angular/angular-cli#11524 or angular/angular-cli#11575
Assignees

Comments

@manoldonev
Copy link
Contributor

Webpack does not work with latest @ngtools/webpack 6.1.0-rc.1:

08:36:40 ERROR in ../node_modules/nativescript-angular/view-util.js
08:36:40 Module not found: Error: Can't resolve '/home/nsbuilduser/workspace/master-TestsAppNg-android/tests-app-ng/node_modules/tns-core-modules/utils' in '/home/nsbuilduser/workspace/master-TestsAppNg-android/tests-app-ng/node_modules/nativescript-angular'
08:36:40  @ ../node_modules/nativescript-angular/view-util.js 2:14-53
08:36:40  @ ../node_modules/nativescript-angular/router/page-router-outlet.js
08:36:40  @ ../node_modules/nativescript-angular/router/router.module.js
08:36:40  @ ../node_modules/nativescript-angular/router/index.js
08:36:40  @ ../platforms/android/app/snapshot-entry.js
08:36:40 
08:36:40 ERROR in ../node_modules/nativescript-angular/router/ns-router-link.js
08:36:40 Module not found: Error: Can't resolve '/home/nsbuilduser/workspace/master-TestsAppNg-android/tests-app-ng/node_modules/tns-core-modules/utils' in '/home/nsbuilduser/workspace/master-TestsAppNg-android/tests-app-ng/node_modules/nativescript-angular/router'
08:36:40  @ ../node_modules/nativescript-angular/router/ns-router-link.js 6:14-53
08:36:40  @ ../node_modules/nativescript-angular/router/router.module.js
08:36:40  @ ../node_modules/nativescript-angular/router/index.js
08:36:40  @ ../platforms/android/app/snapshot-entry.js
08:36:40 
08:36:40 ERROR in ../node_modules/tns-core-modules/ui/builder/component-builder/component-builder.js
08:36:40 Module not found: Error: Can't resolve '/home/nsbuilduser/workspace/master-TestsAppNg-android/tests-app-ng/node_modules/tns-core-modules/utils' in '/home/nsbuilduser/workspace/master-TestsAppNg-android/tests-app-ng/node_modules/tns-core-modules/ui/builder/component-builder'
08:36:40  @ ../node_modules/tns-core-modules/ui/builder/component-builder/component-builder.js 50:20-42
08:36:40  @ ../node_modules/tns-core-modules/ui/builder/builder.js
08:36:40  @ ../node_modules/tns-core-modules/ui/frame/frame.js
08:36:40  @ ../node_modules/tns-core-modules/ui/frame/activity.js
08:36:40  @ ./main.aot.ts
@manoldonev
Copy link
Contributor Author

We need @ngtools/webpack pre-release version for 979f732#diff-8ddd9c5028c697888286c099d3390459

@manoldonev
Copy link
Contributor Author

Issue might be related to angular/angular-cli@47f937e#diff-8357b25ceb65af854095a8bf4ee953d0 ?

@manoldonev
Copy link
Contributor Author

manoldonev commented Jul 10, 2018

More specifically it seems we now have an issue with (at least) tns-core-modules/ui/package.json and tns-core-modules/utils/package.json:

ERROR in ../node_modules/tns-core-modules/ui/scroll-view/scroll-view.js
Module not found: Error: Can't resolve '/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui' in '/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/scroll-view'
resolve '/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui' in '/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/scroll-view'
  using description file: /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/scroll-view/package.json (relative path: .)
    using description file: /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/package.json (relative path: .)
      no extension
        /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui is not a file
      .ts
        /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui.ts doesn't exist
      .js
        /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui.js doesn't exist
      .scss
        /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui.scss doesn't exist
      .css
        /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui.css doesn't exist
      as directory
        existing directory
          using path: /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/index
            using description file: /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/package.json (relative path: ./index)
              no extension
                /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/index doesn't exist
              .ts
                /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/index.ts doesn't exist
              .js
                /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/index.js doesn't exist
              .scss
                /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/index.scss doesn't exist
              .css
                /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/index.css doesn't exist
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui.ts]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui.js]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui.scss]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui.css]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/index]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/index.ts]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/index.js]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/index.scss]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/index.css]
 @ ../node_modules/tns-core-modules/ui/scroll-view/scroll-view.js 7:14-50
 @ ../node_modules/tns-core-modules/bundle-entry-points.js
 @ ./main.ts

ERROR in ../node_modules/nativescript-angular/view-util.js
Module not found: Error: Can't resolve '/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils' in '/Users/mdonev/github/blank-ng2/node_modules/nativescript-angular'
resolve '/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils' in '/Users/mdonev/github/blank-ng2/node_modules/nativescript-angular'
  using description file: /Users/mdonev/github/blank-ng2/node_modules/nativescript-angular/package.json (relative path: .)
    using description file: /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils/package.json (relative path: .)
      no extension
        /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils is not a file
      .ts
        /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils.ts doesn't exist
      .js
        /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils.js doesn't exist
      .scss
        /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils.scss doesn't exist
      .css
        /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils.css doesn't exist
      as directory
        existing directory
          using path: /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils/index
            using description file: /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils/package.json (relative path: ./index)
              no extension
                /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils/index doesn't exist
              .ts
                /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils/index.ts doesn't exist
              .js
                /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils/index.js doesn't exist
              .scss
                /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils/index.scss doesn't exist
              .css
                /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils/index.css doesn't exist
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils.ts]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils.js]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils.scss]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils.css]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils/index]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils/index.ts]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils/index.js]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils/index.scss]
[/Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/utils/index.css]
 @ ../node_modules/nativescript-angular/view-util.js 2:14-53
 @ ../node_modules/nativescript-angular/index.js
 @ ./main.ts

Seems webpack was able to correctly resolve module format previously when https://github.com/angular/angular-cli/blob/63389e5028a33ce57d1fb776c1c8bdbd6004324c/packages/ngtools/webpack/src/paths-plugin.ts#L168 did not happen (i.e. it worked with request.request equal to ui/scroll-view and now it does not work when set to "[absolute-app-path]/node_modules/tns-core-modules/ui/scroll-view)

@dtopuzov dtopuzov added this to the 0.14.4 milestone Jul 10, 2018
@dtopuzov dtopuzov reopened this Jul 10, 2018
@dtopuzov dtopuzov removed this from the 0.14.4 milestone Jul 10, 2018
@manoldonev manoldonev self-assigned this Jul 10, 2018
@hansl
Copy link

hansl commented Jul 10, 2018

@manoldonev Can you confirm this works (or not) with rc.0?

@hansl
Copy link

hansl commented Jul 10, 2018

Seems like it does. You just mentioned rolling back to beta, so I was concerned.

@hansl
Copy link

hansl commented Jul 10, 2018

@manoldonev I'd need some reproduction steps to properly identify this. I can revert the 2 commits that affected the file but I'd like to setup an integration test on our side to prevent this regression in the future.

Could you give me instructions on how to get the error above?

(edit: in case you need some context, I'm the lead on the Angular CLI project)

@manoldonev
Copy link
Contributor Author

@hansl 10x for chiming in.

I am still trying to figure this on our end as well but in short -- we have a folder structure like https://github.com/NativeScript/NativeScript/tree/master/tns-core-modules/ui where the ui folder is not actually a module but https://github.com/NativeScript/NativeScript/blob/master/tns-core-modules/ui/package.json exists with NativeScript specific information. Subdirectories of ui e.g. ui/actionbar, ui/animation are proper modules with their respective package.json. Also, it happens that a stand alone https://github.com/NativeScript/NativeScript/blob/master/tns-core-modules/ui/utils.d.ts in the same ui folder.

At some point while running webpack the paths plugin from @ngtools/webpack receives request to resolve "tns-core-modules/ui/utils" (as originalRequest), with the module resolver this produces /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/utils.d.ts as moduleFilePath in your plugin. But then as noted above your plugin sees that /Users/mdonev/github/blank-ng2/node_modules/tns-core-modules/ui/package.json exists and decides that this must be a module. In our case this particular package.json does not define a module and is unrelated to the utils.d.ts file as far as modules are concerned.

I am working on eliminating such scenarios from our codebase but if you could check whether the package.json contained a "main" field (besides package.json existence) I think we would be good.

@hansl
Copy link

hansl commented Jul 11, 2018

Why not add a main field to your package json (e.g. here) so that webpack knows how to resolve as well? It's technically a package.

@hansl
Copy link

hansl commented Jul 11, 2018

Normally Angular libraries sub-packages are supposed to follow the fESM format (e.g. https://github.com/angular/angular/blob/master/packages/core/testing/package.json)

hansl added a commit to hansl/angular-cli that referenced this issue Jul 11, 2018
If there is a package.json we should also verify that it has a main or fesm field
to see if webpack would actually resolve it properly. Otherwise use the JavaScript
resolution.

This is a temporary fix and still has obvious limitations and issues. Namely, this
code is never run if there is only one path mapping, but that falls outside the
scope of this fix. Also, some people might have valid packages but want to resolve
to the JS file itself (which is what TypeScript does by default). These should be
fixed with a refactoring of the path plugin.

Fixes NativeScript/nativescript-dev-webpack#607
hansl added a commit to hansl/angular-cli that referenced this issue Jul 11, 2018
If there is a package.json we should also verify that it has a main or fesm field
to see if webpack would actually resolve it properly. Otherwise use the JavaScript
resolution.

This is a temporary fix and still has obvious limitations and issues. Namely, this
code is never run if there is only one path mapping, but that falls outside the
scope of this fix. Also, some people might have valid packages but want to resolve
to the JS file itself (which is what TypeScript does by default). These should be
fixed with a refactoring of the path plugin.

Fixes NativeScript/nativescript-dev-webpack#607
@manoldonev
Copy link
Contributor Author

@hansl just for some context -- tns-core-modules is not strictly an Angular library (it powers both Angular, Vue, and JavaScript/TypeScript flavors of our NativeScript framework for native mobile cross-platform development).

@manoldonev
Copy link
Contributor Author

manoldonev commented Jul 12, 2018

@hansl btw I do agree that we could improve our package.json usage and made some modifications across our codebase but I am currently stuck on a rather cryptic Angular compiler runtime error (if I use @ngtoos/webpack 6.1.0-rc.1: file:///app/vendor.js:16816:27: JS ERROR Error: Unexpected value 'undefined' imported by the module 'AppModule'. Unfortunately I do not have a repro for this and I am currently trying to figure out where did that came from.

Again, these same modifications work if I use @ngtools/webpack 6.1.0-rc.0.
Are you planning on releasing rc2 with angular/angular-cli#11524 included at some point that we can test?

hansl added a commit to angular/angular-cli that referenced this issue Jul 12, 2018
If there is a package.json we should also verify that it has a main or fesm field
to see if webpack would actually resolve it properly. Otherwise use the JavaScript
resolution.

This is a temporary fix and still has obvious limitations and issues. Namely, this
code is never run if there is only one path mapping, but that falls outside the
scope of this fix. Also, some people might have valid packages but want to resolve
to the JS file itself (which is what TypeScript does by default). These should be
fixed with a refactoring of the path plugin.

Fixes NativeScript/nativescript-dev-webpack#607
clydin pushed a commit to angular/angular-cli that referenced this issue Jul 12, 2018
If there is a package.json we should also verify that it has a main or fesm field
to see if webpack would actually resolve it properly. Otherwise use the JavaScript
resolution.

This is a temporary fix and still has obvious limitations and issues. Namely, this
code is never run if there is only one path mapping, but that falls outside the
scope of this fix. Also, some people might have valid packages but want to resolve
to the JS file itself (which is what TypeScript does by default). These should be
fixed with a refactoring of the path plugin.

Fixes NativeScript/nativescript-dev-webpack#607
@manoldonev
Copy link
Contributor Author

@hansl I can confirm that we are working correctly with @ngtools/webpack 6.1.0-rc.2

Thank you very much for your responsiveness!

manoldonev added a commit that referenced this issue Jul 13, 2018
We no longer need to hardcode @ngtools/webpack to 6.1.0-rc.0 as #607 is fixed with @ngtools/webpack 6.1.0-rc.2
@manoldonev manoldonev reopened this Jul 16, 2018
@manoldonev
Copy link
Contributor Author

On further testing it seems we still have a problem with rc.2 and the unmodified version of tns-core-modules (i.e. without NativeScript/NativeScript#6067)

@manoldonev
Copy link
Contributor Author

@hansl it is the scenario where we had some folders like https://github.com/NativeScript/NativeScript/tree/master/tns-core-modules/debugger that contained a bulk of d.ts files but only single d.ts (debugger.d.ts) was actually referenced in the folder package.json (that is valid on its own i.e. with "main" field).

When there is a request for tns-core-modules/debugger/devtools-elements.d.ts for example because of the package.json the paths plugin will try to resolve it via tns-core-modules/debugger/debugger.d.ts (that does not know anything about the devtools elements).

@manoldonev
Copy link
Contributor Author

Current logic of paths plugin will only work with the refactored version of tns-core-modules i.e. https://github.com/NativeScript/NativeScript/tree/mdonev/refactor-submodules/tns-core-modules/debugger (submodules introduced) but we need backwards compatibility.

@manoldonev
Copy link
Contributor Author

@hansl Do you need this specific enhancement for the resolution fallback mechanism in @ngtools/webpack? Would it be possible to revert the change so we do not break backwards compatibility on our end?

sis0k0 added a commit to NativeScript/NativeScript that referenced this issue Jul 17, 2018
sis0k0 pushed a commit that referenced this issue Jul 18, 2018
We no longer need to hardcode @ngtools/webpack to 6.1.0-rc.0 as #607 is fixed with @ngtools/webpack 6.1.0-rc.2
sis0k0 added a commit to NativeScript/NativeScript that referenced this issue Jul 18, 2018
sis0k0 added a commit to NativeScript/NativeScript that referenced this issue Jul 18, 2018
sis0k0 pushed a commit that referenced this issue Jul 18, 2018
We no longer need to hardcode @ngtools/webpack to 6.1.0-rc.0 as #607 is fixed with @ngtools/webpack 6.1.0-rc.2
dtopuzov pushed a commit to NativeScript/NativeScript that referenced this issue Jul 18, 2018
* fix: require devtools-elements.js with the extension mentioned explicitly (#6079)

This is a workaround for the issue with `@ngtools/[email protected]`, described here: NativeScript/nativescript-dev-webpack#607 (comment)

* release: cut the 4.1.1 release

* chore: Fix TS transpile error with 2.9 (#5906)
@hansl
Copy link

hansl commented Jul 19, 2018

@manoldonev Hi, I released RC3 yesterday. Can you try it? It reverted the faulty PR entirely.

@sis0k0
Copy link
Contributor

sis0k0 commented Jul 19, 2018

Hey @hansl! I can confirm that updating to @ngtools/webpack 6.1.0-rc.3 fixes the issue.

@sis0k0 sis0k0 closed this as completed Jul 19, 2018
ikjelle pushed a commit to ikjelle/angular-cli that referenced this issue Mar 26, 2024
If there is a package.json we should also verify that it has a main or fesm field
to see if webpack would actually resolve it properly. Otherwise use the JavaScript
resolution.

This is a temporary fix and still has obvious limitations and issues. Namely, this
code is never run if there is only one path mapping, but that falls outside the
scope of this fix. Also, some people might have valid packages but want to resolve
to the JS file itself (which is what TypeScript does by default). These should be
fixed with a refactoring of the path plugin.

Fixes NativeScript/nativescript-dev-webpack#607
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants