Search code examples
typescriptgulpbrowserify

"Cannot find module 'three' from"


I'm having a hard time migrating my toy typescript app at http://ssrb.github.io/mega-structure/mega-structure.html from typings to @types/npm.

The error I can't figure out is Error: Cannot find module 'three' and Error: Cannot find module 'codemirror'

The workflow is typescript/gulp/browserify.

For that migration, I deleted my typings.json as well as all the typing stuff from my gulpfile and npm install @types.

Then I fixed a few errors due to some API changes after upgrading the type definitions.

I replaced ///<reference path="typings/index.d.ts"/> with some import * as THREE from 'three';

It now fails to bundle and I'm trying to figure it out without success:

[13:41:56] Using gulpfile mega-structure/gulpfile.js
[13:41:56] Starting 'default'...
[13:41:56] Starting '.bower.install'...
[13:41:58] Using cwd: mega-structure
[13:41:58] Using bower dir: ./bower_components
[13:42:01] Finished '.bower.install' after 4.99 s
[13:42:01] Starting '.peg'...
[13:42:01] Finished '.peg' after 131 ms
[13:42:01] Starting '.examples'...


[13:42:01] Finished '.examples' after 155 ms
[13:42:01] Starting '.ui.release'...
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: Cannot find module 'three' from 'mega-structure'
    at mega-structure/node_modules/browser-resolve/node_modules/resolve/lib/async.js:46:17
    at process (mega-structure/node_modules/browser-resolve/node_modules/resolve/lib/async.js:173:43)
    at ondir (mega-structure/node_modules/browser-resolve/node_modules/resolve/lib/async.js:188:17)
    at load (mega-structure/node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43)
    at onex (mega-structure/node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31)
    at mega-structure/node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:152:21)

See https://github.com/ssrb/mega-structure/commit/3285f5cb45c110d87ea5db795e47a4a392a15c1f and https://travis-ci.org/ssrb/mega-structure/builds/359637820?utm_source=email&utm_medium=notification


Solution

  • The problem was that the build was consuming type declarations forthree.js, codemirror, ... installed with npm but the matching javascript libraries were still installed using bower. After installing the libraries with npm rather than bower the build recovered.