项目在开发中运行良好,但在尝试构建平台(android)时,错误正在发生。
注意:
命令 ionic cordova build android --prod --release
返回错误以下;
Module not found: Error: Can't resolve 'api/collections' in '/home/noshu/code/ptc-gps/nexxdeli-mobile/src/pages/user/user-profile-edit'
resolve 'api/collections' in '/home/noshu/code/ptc-gps/nexxdeli-mobile/src/pages/user/user-profile-edit'
Parsed request is a module
using description file: /home/noshu/code/ptc-gps/nexxdeli-mobile/package.json (relative path: ./src/pages/user/user-profile-edit)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /home/noshu/code/ptc-gps/nexxdeli-mobile/package.json (relative path: ./src/pages/user/user-profile-edit)
resolve as module
/home/noshu/code/ptc-gps/nexxdeli-mobile/src/pages/user/user-profile-edit/node_modules doesn't exist or is not a directory
/home/noshu/code/ptc-gps/nexxdeli-mobile/src/pages/user/node_modules doesn't exist or is not a directory
/home/noshu/code/ptc-gps/nexxdeli-mobile/src/pages/node_modules doesn't exist or is not a directory
/home/noshu/code/ptc-gps/nexxdeli-mobile/src/node_modules doesn't exist or is not a directory
/home/noshu/code/ptc-gps/node_modules doesn't exist or is not a directory
/home/noshu/code/node_modules doesn't exist or is not a directory
/home/noshu/node_modules doesn't exist or is not a directory
/home/node_modules doesn't exist or is not a directory
/node_modules doesn't exist or is not a directory
looking for modules in /home/noshu/code/ptc-gps/nexxdeli-mobile/node_modules
using description file: /home/noshu/code/ptc-gps/nexxdeli-mobile/package.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /home/noshu/code/ptc-gps/nexxdeli-mobile/package.json (relative path: ./node_modules)
using description file: /home/noshu/code/ptc-gps/nexxdeli-mobile/package.json (relative path: ./node_modules/api/collections)
no extension
Field 'browser' doesn't contain a valid alias configuration
/home/noshu/code/ptc-gps/nexxdeli-mobile/node_modules/api/collections doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/home/noshu/code/ptc-gps/nexxdeli-mobile/node_modules/api/collections.js doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
/home/noshu/code/ptc-gps/nexxdeli-mobile/node_modules/api/collections.ts doesn't exist
as directory
/home/noshu/code/ptc-gps/nexxdeli-mobile/node_modules/api/collections doesn't exist
[/home/noshu/code/ptc-gps/nexxdeli-mobile/src/pages/user/user-profile-edit/node_modules]
[/home/noshu/code/ptc-gps/nexxdeli-mobile/src/pages/user/node_modules]
[/home/noshu/code/ptc-gps/nexxdeli-mobile/src/pages/node_modules]
[/home/noshu/code/ptc-gps/nexxdeli-mobile/src/node_modules]
[/home/noshu/code/ptc-gps/node_modules]
[/home/noshu/code/node_modules]
[/home/noshu/node_modules]
[/home/node_modules]
[/node_modules]
[/home/noshu/code/ptc-gps/nexxdeli-mobile/node_modules/api/collections]
[/home/noshu/code/ptc-gps/nexxdeli-mobile/node_modules/api/collections.js]
[/home/noshu/code/ptc-gps/nexxdeli-mobile/node_modules/api/collections.ts]
[/home/noshu/code/ptc-gps/nexxdeli-mobile/node_modules/api/collections]
@ ./src/pages/user/user-profile-edit/user-profile-edit.page.js 5:20-46
@ ./src/app/app.module.js
@ ./src/app/app.module.ngfactory.js
@ ./src/app/main.ts
下面是文件夹结构;
webpack.config.js;
var path = require('path');
var webpack = require('webpack');
var ionicWebpackFactory = require(process.env.IONIC_WEBPACK_FACTORY);
module.exports = {
entry: process.env.IONIC_APP_ENTRY_POINT,
output: {
path: '{{BUILD}}',
publicPath: 'build/',
filename: process.env.IONIC_OUTPUT_JS_FILE_NAME,
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
},
devtool: process.env.IONIC_SOURCE_MAP_TYPE,
resolve: {
extensions: ['.ts', '.js', '.json'],
modules: [
// /home/noshu/code/ptc-gps/nexxdeli-mobile/node_modules
path.resolve('node_modules')
],
alias: {
'api': path.resolve(__dirname, 'api/server')
}
},
externals: [
resolveExternals
],
module: {
loaders: [
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.ts$/,
loader: process.env.IONIC_WEBPACK_LOADER
},
{
test: /\.js$/,
loader: process.env.IONIC_WEBPACK_TRANSPILE_LOADER
}
]
},
plugins: [
ionicWebpackFactory.getIonicEnvironmentPlugin(),
new webpack.ProvidePlugin({
__extends: 'typescript-extends'
})
],
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: 'empty',
net: 'empty',
tls: 'empty',
__dirname: true
}
};
function resolveExternals(context, request, callback) {
return resolveMeteor(request, callback) ||
callback();
}
function resolveMeteor(request, callback) {
var match = request.match(/^meteor\/(.+)$/);
var pack = match && match[1];
if (pack) {
callback(null, 'Package["' + pack + '"]');
return true;
}
}
tsconfig.json;
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "commonjs",
"moduleResolution": "node",
"paths": {
"api/*": ["./api/server/*"]
},
"sourceMap": true,
"target": "es5",
"skipLibCheck": true,
"stripInternal": true,
"noImplicitAny": false,
"noEmitHelpers": true,
"types": [
/*"@types/underscore"*/
]
},
"include": [
"src/**/*.ts",
"api/**/*.ts"
],
"exclude": [
"node_modules",
"api/node_modules",
"api"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
的package.json;
{
"name": "Nexxdeli-App",
"version": "0.0.1",
"author": "MRHASAN/ptc-gps.de",
"homepage": "http://ptc-gps.de",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve",
"meteor-client:bundle": "meteor-client bundle -s api -c meteor-client.config.json"
},
"dependencies": {
"@angular/common": "4.1.3",
"@angular/compiler": "4.1.3",
"@angular/compiler-cli": "4.1.3",
"@angular/core": "4.1.3",
"@angular/forms": "4.1.3",
"@angular/http": "4.1.3",
"@angular/platform-browser": "4.1.3",
"@angular/platform-browser-dynamic": "4.1.3",
"@ionic-native/core": "3.12.1",
"@ionic-native/splash-screen": "3.12.1",
"@ionic-native/status-bar": "3.12.1",
"@ionic/storage": "^2.0.1",
"angular2-meteor-accounts-ui": "^1.0.0",
"aws-sdk": "^2.95.0",
"babel-runtime": "^6.23.0",
"cordova-android": "^6.2.3",
"cordova-plugin-console": "^1.0.7",
"cordova-plugin-device": "^1.1.6",
"cordova-plugin-fcm": "^2.1.2",
"cordova-plugin-splashscreen": "^4.0.3",
"cordova-plugin-statusbar": "^2.2.3",
"cordova-plugin-whitelist": "^1.3.2",
"cordova-sqlite-storage": "^2.0.4",
"ionic-angular": "3.5.0",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "3.0.0",
"meteor-node-stubs": "^0.2.11",
"meteor-rxjs": "^0.4.7",
"rxjs": "5.4.0",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.12"
},
"devDependencies": {
"@ionic/app-scripts": "2.0.1",
"@ionic/cli-plugin-cordova": "1.6.2",
"@ionic/cli-plugin-ionic-angular": "1.4.1",
"@types/meteor": "^1.4.2",
"@types/underscore": "^1.8.1",
"ionic": "3.7.0",
"meteor-typings": "^1.4.1",
"tmp": "0.0.31",
"ts-helpers": "^1.1.2",
"typescript": "2.3.4",
"typescript-extends": "^1.0.1"
},
"description": "Nexxdeli Ionic project",
"config": {
"ionic_webpack": "./webpack.config.js"
},
"cordova": {
"plugins": {
"cordova-plugin-console": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-whitelist": {},
"ionic-plugin-keyboard": {},
"cordova-plugin-fcm": {},
"cordova-sqlite-storage": {}
},
"platforms": [
"android"
]
}
}
答案 0 :(得分:0)
Ionic-CLI希望所有导入都位于src
目录中。因此,要修复--prod
构建,只需将api
目录移动到src
目录中即可。
在这里,您可以找到ionic cordova run android --prod
适用于生产版本的小示例:
https://drive.google.com/open?id=1QRo0PQLXYCRG6nc-nO6lECzjya-8oMLk
更多信息: https://github.com/Urigo/Ionic2CLI-Meteor-WhatsApp/issues/113#issuecomment-342187908