2016-04-22 6 views
0

Mein Webpack-Dev-Server funktioniert ohne Probleme mit meinen bestehenden Abhängigkeiten.Wie wird bugsense.js über das Webpack geladen?

Jetzt möchte ich bugsense in meinem Projekt verwenden. Die bugsense-Bibliothek befindet sich nicht im npm-Repository. Diese

ist, wie ich es in meinem package.json umfassen

"dependencies": { 
    "bootstrap": "^3.3.6", 
    "bugsense": "bugsense/bugsense.js", 
    ... 

Das Paket von Github heruntergeladen wurde, wie erwartet.

aber als ich versuchte, es in einem es6 js Skript zu importieren, wie so

import bugsense from 'bugsense'; 

bekam ich diese Fehlermeldung

Module not found: Error: Cannot resolve module 'bugsense' in /Users/antkong/dev/projects/web/app/scripts/actions 
resolve module bugsense in /Users/antkong/dev/projects/web/app/scripts/actions 
    looking for modules in /Users/antkong/dev/projects/webview/node_modules 
    /Users/antkong/dev/projects/webview/node_modules/bugsense doesn't exist (module as directory) 
    resolve 'file' bugsense in /Users/antkong/dev/projects/webview/node_modules 
     resolve file 
     /Users/antkong/dev/projects/webview/node_modules/bugsense doesn't exist 
     /Users/antkong/dev/projects/webview/node_modules/bugsense.webpack.js doesn't exist 
     /Users/antkong/dev/projects/webview/node_modules/bugsense.web.js doesn't exist 
     /Users/antkong/dev/projects/webview/node_modules/bugsense.js doesn't exist 
     /Users/antkong/dev/projects/webview/node_modules/bugsense.json doesn't exist 
    looking for modules in /Users/antkong/dev/projects/web/node_modules 
    resolve 'file' bugsense in /Users/antkong/dev/projects/web/node_modules 
     resolve file 
     /Users/antkong/dev/projects/web/node_modules/bugsense is not a file 
     /Users/antkong/dev/projects/web/node_modules/bugsense.webpack.js doesn't exist 
     /Users/antkong/dev/projects/web/node_modules/bugsense.web.js doesn't exist 
     /Users/antkong/dev/projects/web/node_modules/bugsense.js doesn't exist 
     /Users/antkong/dev/projects/web/node_modules/bugsense.json doesn't exist 
    resolve 'file' or 'directory' /Users/antkong/dev/projects/web/node_modules/bugsense 
     resolve file 
     /Users/antkong/dev/projects/web/node_modules/bugsense is not a file 
     /Users/antkong/dev/projects/web/node_modules/bugsense.webpack.js doesn't exist 
     /Users/antkong/dev/projects/web/node_modules/bugsense.web.js doesn't exist 
     /Users/antkong/dev/projects/web/node_modules/bugsense.js doesn't exist 
     /Users/antkong/dev/projects/web/node_modules/bugsense.json doesn't exist 
     resolve directory 
     directory default file index 
      resolve file index in /Users/antkong/dev/projects/web/node_modules/bugsense 
      /Users/antkong/dev/projects/web/node_modules/bugsense/index doesn't exist 
      /Users/antkong/dev/projects/web/node_modules/bugsense/index.webpack.js doesn't exist 
      /Users/antkong/dev/projects/web/node_modules/bugsense/index.web.js doesn't exist 
      /Users/antkong/dev/projects/web/node_modules/bugsense/index.js doesn't exist 
      /Users/antkong/dev/projects/web/node_modules/bugsense/index.json doesn't exist 
     use ./lib/node/index.js from package.json 
      resolve 'file' or 'directory' ./lib/node/index.js in /Users/antkong/dev/projects/web/node_modules/bugsense 
      resolve file 
       /Users/antkong/dev/projects/web/node_modules/bugsense/lib/node/index.js.webpack.js doesn't exist 
       /Users/antkong/dev/projects/web/node_modules/bugsense/lib/node/index.js doesn't exist 
       /Users/antkong/dev/projects/web/node_modules/bugsense/lib/node/index.js.web.js doesn't exist 
       /Users/antkong/dev/projects/web/node_modules/bugsense/lib/node/index.js.js doesn't exist 
       /Users/antkong/dev/projects/web/node_modules/bugsense/lib/node/index.js.json doesn't exist 
      resolve directory 
       /Users/antkong/dev/projects/web/node_modules/bugsense/lib/node/index.js doesn't exist (directory default file) 
       /Users/antkong/dev/projects/web/node_modules/bugsense/lib/node/index.js/package.json doesn't exist (directory description file) 
[/Users/antkong/dev/projects/web/node_modules/bugsense.webpack.js] 
[/Users/antkong/dev/projects/web/node_modules/bugsense.webpack.js] 
[/Users/antkong/dev/projects/web/node_modules/bugsense.web.js] 
[/Users/antkong/dev/projects/web/node_modules/bugsense.web.js] 
[/Users/antkong/dev/projects/web/node_modules/bugsense.js] 
[/Users/antkong/dev/projects/web/node_modules/bugsense.js] 
[/Users/antkong/dev/projects/web/node_modules/bugsense.json] 
[/Users/antkong/dev/projects/web/node_modules/bugsense.json] 
[/Users/antkong/dev/projects/webview/node_modules/bugsense] 
[/Users/antkong/dev/projects/webview/node_modules/bugsense] 
[/Users/antkong/dev/projects/webview/node_modules/bugsense.webpack.js] 
[/Users/antkong/dev/projects/webview/node_modules/bugsense.web.js] 
[/Users/antkong/dev/projects/webview/node_modules/bugsense.js] 
[/Users/antkong/dev/projects/webview/node_modules/bugsense.json] 
[/Users/antkong/dev/projects/web/node_modules/bugsense/index] 
[/Users/antkong/dev/projects/web/node_modules/bugsense/index.webpack.js] 
[/Users/antkong/dev/projects/web/node_modules/bugsense/index.web.js] 
[/Users/antkong/dev/projects/web/node_modules/bugsense/index.js] 
[/Users/antkong/dev/projects/web/node_modules/bugsense/index.json] 
[/Users/antkong/dev/projects/web/node_modules/bugsense/lib/node/index.js.webpack.js] 
[/Users/antkong/dev/projects/web/node_modules/bugsense/lib/node/index.js] 
[/Users/antkong/dev/projects/web/node_modules/bugsense/lib/node/index.js.web.js] 
[/Users/antkong/dev/projects/web/node_modules/bugsense/lib/node/index.js.js] 
[/Users/antkong/dev/projects/web/node_modules/bugsense/lib/node/index.js.json] 
@ ./app/scripts/actions/someActions.js 21:16-35 

Webpack versagt das Modul aufgrund einer fehlenden Datei zu laden.

Wie kann ich es beheben? Kann ich es einfach über eine Webpack-Konfiguration reparieren?

Antwort

1

Das Problem ist, dass Bugsense das Feld main ihrer package.json nicht richtig eingestellt hat. Webpack ermittelt auf dieser Basis, wo die Bibliothek abgerufen werden soll.

Um dies zu umgehen, können Sie eine resolve.alias wie folgt definieren könnte:

{ 
    resolve: { 
    alias: { 
     bugsense: path.join(__dirname, 'bugsense/bugsense.js/lib/amd/bugsense.js') 
    } 
    } 
} 

Sie müssen möglicherweise mit diesem Weg experimentieren.

Sie können auch darauf achten, auf die verkleinerte Version zu zeigen und dann module.noParse so einzustellen, dass webpack die Analyse der Datei vermeiden kann. Dies könnte zu einer zusätzlichen Leistung führen.