Learn about modules from inflearn (1) During lecture practice during angular practice Uncaught (inpromise) Error: Fetch error: 404 Not Found error.
The modules are configured as follows.
Angular CLI: 1.6.0
Node: 8.9.3
OS: win32 x64
first-app/src/index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>FirstApp</title>
<base href="/">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/systemjs/dist/system.js"></script>
<script>
SystemJS.config({
baseURL: '/first-app/src/module',
transpiler: 'plugin-babel',
map:{
'plugin-babel':'https://unpkg.com/systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build': 'https://unpkg.com/systemjs-plugin-babel/systemjs-babel-browser.js'
}
});
SystemJS.import('main.js');
</script>
</head>
<body>
<app-root></app-root>
</body>
</html>
first-app/src/module/module.js
import {greeting} from 'greeting.js'
greeting('great!!!!!')
first-app/src/module/greeting.js
export function greeting(name){
console.log(name);
}
The rest of the configuration remains in the "ng new app name" state.
angular
It's been resolved.
1. In the root path.Added to angular-cli.json as below.
“assets”: [
"module", // Here..
“assets”,
“favicon.ico”
],
2. Modify SystemJS.config
SystemJS.config({
baseURL: '/module',
transpiler: 'plugin-babel',
map:{
'plugin-babel':'https://unpkg.com/systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build': 'https://unpkg.com/systemjs-plugin-babel/systemjs-babel-browser.js'
}
});
3. Restart after ending ngserve
Reference: See also Yoon Tae-gun's reply
© 2024 OneMinuteCode. All rights reserved.