darkbasic / angularcli-meteor

13 stars 4 forks source link

Tests: Module not found: Error: Can't resolve 'meteor/meteor' #2

Open rgal75 opened 6 years ago

rgal75 commented 6 years ago

In an attempt to write a karma test in the angularcli-meteor template, I added a test case, which depends on Meteor by importing 'meteor/meteor' in a class under test. Then, if I issue $> npm run test I get Module not found: Error: Can't resolve 'meteor/meteor'

To easily reproduce the issue, modify app.component.ts by calling anything on Meteor. E.g.

...
import { Meteor } from 'meteor/meteor'
...
ngOnInit() {
    console.log(Meteor.release)
    ...
  }

and run $> npm run test

darkbasic commented 6 years ago

https://github.com/angular/angular-cli/issues/8086 Unfortunately this is a known issue with no solution yet. It seems that webpack does not honour externals when running tests.

rgal75 commented 6 years ago

Having read angular/angular-cli#8086 I can see that the issue is about Uncaught ReferenceError: Mongo is not defined. I was able to overcome this by importing 'meteor-client' in test.ts.

I suspect that the issue I reported may have a different cause.

rgal75 commented 6 years ago

It looks to me that Karma is still using AngularCli to build the tests instead of the ejected and modified webpack.config that has the

externals: [
        resolveExternals
    ]

configuration and as a result the tests cannot see the meteor/* modules. What do you think?

darkbasic commented 6 years ago

I'm not sure, but the Mongo error was definitely an oversight from my side.

michaelb-01 commented 6 years ago

I'm getting the same error (though main.ts now has import 'meteor-client';)


 10% building modules 3/3 modules 0 activeProject is running at http://localhost:4200/
webpack output is served from /
404s will fallback to /index.html
Hash: 78794858705e820c1ae5                                                              
Version: webpack 3.6.0
Time: 11832ms
 10 assets
[./node_modules/@angular/core/@angular/core.es5.js] ./node_modules/@angular/core/@angular/core.es5.js 492 kB {vendor} [built]
[./node_modules/core-js/es7/reflect.js] ./node_modules/core-js/es7/reflect.js 510 bytes {polyfills} [built]
[./node_modules/loglevel/lib/loglevel.js] ./node_modules/loglevel/lib/loglevel.js 7.86 kB {inline} [built]
[./node_modules/webpack-dev-server/client/index.js?http://localhost:4200] (webpack)-dev-server/client?http://localhost:4200 5.83 kB {inline} [built]
[./node_modules/webpack/hot ^\.\/log$] (webpack)/hot nonrecursive ^\.\/log$ 170 bytes {inline} [built]
[./node_modules/webpack/hot/emitter.js] (webpack)/hot/emitter.js 77 bytes {inline} [built]
   [0] multi (webpack)-dev-server/client?http://localhost:4200 ./src/main.ts 40 bytes {main} [built]
   [1] multi (webpack)-dev-server/client?http://localhost:4200 ./src/polyfills.ts 40 bytes {polyfills} [built]
[./node_modules/zone.js/dist/zone.js] ./node_modules/zone.js/dist/zone.js 126 kB {polyfills} [built]
[./src/app/app.module.ts] ./src/app/app.module.ts 1.11 kB {main} [built]
[./src/environments/environment.ts] ./src/environments/environment.ts 509 bytes {main} [built]
[./src/main.ts] ./src/main.ts 447 bytes {main} [built]
   [2] multi (webpack)-dev-server/client?http://localhost:4200 ./src/styles.scss 40 bytes {styles} [built]
[./src/polyfills.ts] ./src/polyfills.ts 2.52 kB {polyfills} [built]
[./src/styles.scss] ./src/styles.scss 1.24 kB {styles} [built]
    + 654 hidden modules

ERROR in ./src/main.ts
Module not found: Error: Can't resolve 'meteor-client' in '/Users/michaelbattcock/Documents/dev/apps/angularcli-meteor-master/src'
 @ ./src/main.ts 1:0-23
 @ multi (webpack)-dev-server/client?http://localhost:4200 ./src/main.ts
Child html-webpack-plugin for "index.html":
     1 asset
    [./node_modules/html-webpack-plugin/lib/loader.js!./src/index.html] ./node_modules/html-webpack-plugin/lib/loader.js!./src/index.html 352 bytes {0} [built]
webpack: Failed to compile.
michaelb-01 commented 6 years ago

I've resolved the build error by doing npm install meteor-client

But now i'm getting:

vendor.bundle.js:67016 Uncaught ReferenceError: Mongo is not defined
    at new Collection (vendor.bundle.js:67016)
    at Object../api/server/collections/chats.ts (main.bundle.js:10)
    at __webpack_require__ (inline.bundle.js:55)
    at Object../api/server/collections/index.ts (main.bundle.js:19)
    at __webpack_require__ (inline.bundle.js:55)
    at Object../src/app/app.component.ts (main.bundle.js:89)
    at __webpack_require__ (inline.bundle.js:55)
    at Object../src/app/app.module.ts (main.bundle.js:133)
    at __webpack_require__ (inline.bundle.js:55)
    at Object../src/main.ts (main.bundle.js:191)
darkbasic commented 6 years ago

Did you run npm run meteor-client:bundle?

michaelb-01 commented 6 years ago

Sorry no I hand't, ignore me! It works now!

janKir commented 6 years ago

I'm running into the same error. Is there a solution or workaround, yet?

Edit: I experience the error Error: Module not found: Error: Can't resolve 'meteor/meteor' as described above. I also experience this issue on a fresh clone of this repo. And I'm a little confused, that it seems to work for @michaelb-01 ?!