Ionic 3: Build in “prod” mode: Cannot find module “.”

淺唱寂寞╮ 提交于 2019-12-01 16:34:27

问题


we have a large Ionic app that we’re trying to build in production mode since it’s almost ready. The first issue we found is that we were getting a “JavaScript heap out of memory” error when compiling, but we fixed it by giving more memory to node:

"ionic:build": "node --max-old-space-size=16384 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build",

npm run ionic:build -- --prod

With this command the app successfully builds, but if I open it I get the following error:

Uncaught Error: Cannot find module “.”
at vendor.js:1
at vendor.js:1
at Object. (vendor.js:1)
at e (vendor.js:1)
at Object. (main.js:1)
at e (vendor.js:1)
at window.webpackJsonp (vendor.js:1)
at main.js:1

I searched a bit and I found that it could be caused by require, but we aren’t using it. Any idea of what could be going on or what we can do to debug the issue? Is there any way to use “–-prod” without minifying the JS?

This is my environment:

cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0
global packages:

cordova (Cordova CLI) : 6.5.0 
Gulp CLI              : [09:06:54] CLI version 3.9.1 [09:06:54] Local version 3.9.1
local packages:

@ionic/app-scripts : 3.1.9
Cordova Platforms  : android 6.1.2 ios 4.3.1
Ionic Framework    : ionic-angular 3.9.2
System:

Android SDK Tools : 25.2.5
ios-deploy        : 1.9.1 
ios-sim           : 5.0.8 
Node              : v8.6.0
npm               : 5.3.0 
OS                : macOS High Sierra
Xcode             : Xcode 9.3.1 Build version 9E501 
Misc:

backend : legacy

Thank you!


回答1:


I found the problem. In my package.json I was using:

"typescript": "^2.9.1",

Decreasing the version to ~2.6.2 fixed it for me.




回答2:


Removing ^ from @ionic/app-scripts and typescript works for me as follows:

"devDependencies": {
    "@ionic/app-scripts": "3.1.9",
    "typescript": "2.8.3"
  }



回答3:


I had a similar problem, but the wrong typescript package was getting pulled in from a combination of other dependent projects as well as VS Code. I resolved it by pinning the exact version (no ^ or ~) of @ionic/app-scripts and typescript to what I needed.

"devDependencies": { "@ionic/app-scripts": "3.1.9", "typescript": "2.6.2" }




回答4:


Got this error with a new version and I checked the ionic-angular imports and it's fine.

package.json

"typescript": "3.1.6"

Ionic info

 ionic (Ionic CLI)  : 4.4.0
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

   cordova (Cordova CLI) : 8.1.1 (cordova-lib@8.1.0)
   Cordova Platforms     : android 7.0.0, browser 5.0.3
   Cordova Plugins       : no whitelisted plugins (0 plugins total)

error

vendor.js:138159 Uncaught Error: Cannot find module "."
    at webpackMissingModule (vendor.js:138159)
    at vendor.js:138159
    at Object.<anonymous> (vendor.js:138168)
    at __webpack_require__ (vendor.js:55)
    at Object.<anonymous> (main.js:16031)
    at __webpack_require__ (vendor.js:55)
    at webpackJsonpCallback (vendor.js:26)
    at main.js:1


来源:https://stackoverflow.com/questions/50713430/ionic-3-build-in-prod-mode-cannot-find-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!