Reputation: 2322
Using Aurelia latest and webpack, running npm run watch
, I get the following error in the browser and the app does not load:
Uncaught (in promise) No PLATFORM.Loader is defined and there is neither a System API (ES6) or a Require API (AMD) globally available to load your app
I think the PLATFORM (from aurelia-pal
) is not available at run time for some reason. Below is info that I hope is sufficient to understand what's wrong.
Here is my webpack.config.js
:
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { AureliaPlugin, ModuleDependenciesPlugin } = require("aurelia-webpack-plugin");
const optimize = webpack.optimize;
module.exports = {
entry: {
main: "./src/main.ts",
vendor: [ "aurelia-bootstrapper" ]
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js"
},
resolve: {
extensions: [".ts", ".js"],
modules: ["src", "node_modules"].map(x => path.resolve(x))
},
devServer: {
contentBase: path.resolve(__dirname, "dist"),
// serve index.html for all 404 (required for push-state)
historyApiFallback: true
},
mode: "development",
devtool: "inline-source-map",
optimization: {
minimize: false
},
module: {
rules: [
{
enforce: "pre",
test: /.ts$/,
use: "source-map-loader"
},
{
test: /\.css$/i,
use: [{
loader: "css-loader",
options: {
sourceMap: true
}
}]
},
{
test: /\.less$/i,
use: [{
loader: "css-loader",
options: {
sourceMap: true
}
},
{
loader: "less-loader",
options: {
sourceMap: true
}
}]
},
{
test: /\.ts$/i,
use: "ts-loader"
},
{
test: /\.html$/i,
use: "html-loader"
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [{
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/font-woff',
name: 'fonts/[name].[ext]'
}
}]
},
{
test: /\.(eot|svg|ttf)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [{
loader: 'file-loader'
}]
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html"
}),
new AureliaPlugin()
]
};
And my package.json
:
{
"name": "ts-webpack-starter",
"version": "1.0.0",
"main": "index.js",
"author": "Benny Halperin",
"license": "MIT",
"scripts": {
"lint": "tslint src/**/*.ts",
"watch": "yarn webpack-dev-server --config webpack.dev.js --hot --inline --progress",
"_watch": "webpack-dashboard webpack-dev-server --config webpack.dev.js --hot --inline --progress",
"build:prod": ""
},
"devDependencies": {
"@types/jasmine": "^2.8.6",
"aurelia-testing": "^1.0.0-beta.4.0.0",
"aurelia-webpack-plugin": "^3.0.0-rc.1",
"awesome-typescript-loader": "^5.0.0",
"css-loader": "^0.28.11",
"file-loader": "^1.1.11",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"jasmine": "^3.1.0",
"jasmine-core": "^3.1.0",
"jasmine-ts": "^0.2.1",
"karma": "^2.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-headless-chrome-launcher": "^0.0.6",
"karma-jasmine": "^1.1.1",
"karma-phantomjs-launcher": "^1.0.4",
"karma-typescript": "^3.0.12",
"karma-webpack": "^3.0.0",
"less": "^3.0.1",
"less-loader": "^4.1.0",
"source-map-loader": "^0.2.3",
"style-loader": "^0.20.3",
"ts-loader": "^4.2.0",
"tslib": "^1.9.0",
"tslint": "^5.9.1",
"typescript": "^2.8.1",
"url-loader": "^1.0.1",
"webpack": "^4.5.0",
"webpack-cli": "^2.0.14",
"webpack-dashboard": "^1.1.1",
"webpack-dev-server": "^3.1.2",
"webpack-merge": "^4.1.2"
},
"dependencies": {
"aurelia-bootstrap": "^0.1.20",
"aurelia-bootstrapper": "^2.2.0",
"aurelia-fetch-client": "^1.3.1",
"aurelia-framework": "^1.2.0",
"aurelia-google-maps": "^2.2.1",
"bootstrap": "^4.0.0",
"firebase": "^4.12.1",
"font-awesome": "^4.7.0"
}
}
Upvotes: 1
Views: 448
Reputation: 8047
You could try installing aurelia-loader
as a dependency explicitly. Normally shouldn't be needed though. I personally like to have all my aurelia dependencies explicitly installed. Sure there's 20 of them, but how often do you look at package.json anyway..
Some other potential issues I noticed:
Pretty sure you're not supposed to have main.ts
referenced in your webpack config. This is the typical entry configuration:
entry: {
app: ["aurelia-bootstrapper"],
vendor: ["bluebird"]
},
aurelia-bootstrapper will locate your main.ts based on the aurelia-app
attribute in your index.html. And aurelia-webpack-plugin
will ensure that it's included. Vendor may or may not be omitted entirely (not actually sure if the webpack plugin explicitly looks for this), but app should be aurelia-bootstrapper
afaik.
I also see you don't have bluebird installed. Maybe firebase includes promises already, but you probably want to keep bluebird regardless (can opt for the .core
variant if size is a concern). There's no better performing promise library out there (there's a good reason Aurelia has it in the project template)
Upvotes: 1