聞きたいこと
モジュールのインポートをする箇所で、下のようなエラーが発生してしまい解決できません。。
モジュールインポートの際にパスで記述する際のエラーのようですが、、、絶対パス等で入力しても解決せず・・・
- エラー内容
Uncaught TypeError: Failed to resolve module specifier "SpriteSheet". Relative references must start with either "/", "./", or "../".
- ディレクトリ構成
: - public |- js |- main.js |- SpriteSheet.js |- loaders.js |- img :
- main.js
javascript
1import SpriteSheet from './SpriteSheet'; 2import {loadImage, loadLevel} from './loaders'; 3 4function drawBackground(background, context, sprites) { 5 background.ranges.forEach(([x1, x2, y1, y2]) => { 6 for (let x = x1; x < x2; ++x) { 7 for (let y = y1; y < y2; ++y) { 8 sprites.drawTile(background.tile, context, x, y); 9 } 10 } 11 }); 12}
- SpriteSheet.js
export default class SpriteSheet { constructor (image, width, height) { this.image = image; this.width = width; this.height = height; this.tiles = new Map(); } define(name, x, y) { const buffer = document.createElement('canvas'); buffer.width = this.width; buffer.height = this.height; buffer .getContext('2d') .drawImage( x * this.width, y * this.height, this.width, this.height, 0, 0, this.width, this,height); this.tiles.set(name, buffer); } draw(name, context, x, y) { const buffer = this.tiles.get(name); context.drawImage(buffer, x, y); } drawTile(name, context, x, y) { this.draw(name, context, x * this.width, y * this.height); } }
- loaders.js
export function loadImage(url) { return new Promise(resolve => { const image = new Image(); image.addEventListener('load', () => { resolve(image); }); image.src = url; }); } export function loadLevel(name) { return fetch(`/levels${name}.json`) .then(r => r.json()); }
- package.json
{ "name": "super-mario", "version": "1.0.0", "description": "", "main": "main.js", "scripts": { "start": "serve ./public", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "serve": "^10.0.2" } }
- Chrome version: 70
以上となります。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。