mikach / requirejs-babel

An AMD loader plugin for Babel
117 stars 32 forks source link

path and file extension errors loading lit-html #34

Open wkeese opened 4 years ago

wkeese commented 4 years ago

The es6! plugin can't load lit-html due to problems with relative paths and file extensions. To reproduce, do an

npm install lit-html

add the entry below to paths in index.html:

'lit-html': '../node_modules/lit-html/lit-html',

and then modify demo/class.js to load lit-html:

import {html, render} from 'lit-html';

It fails trying to GET:

requirejs-babel/demo/lib/default-template-processor.js.js 

There are (at least) two problems here:

(1) The es6.js code appends fileExtension even for import statements that already have a file extension. lit-html.js has imports like below that specify the .js extension:

import { defaultTemplateProcessor } from './lib/default-template-processor.js';

As per the examples in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import, putting the .js in the import statement is actually not an error.

(2) Relative paths aren't working correctly. The ./ in the import statement above should be relative to the directory where lit-html.js is. Instead, it's evaluating relative to the directory where class.js is.

prantlf commented 2 years ago

Appending the .js extension did need a fix. But loading lit-html just works in my example.