Lwc: [@lwc/rollup-plugin] can't import modules with default values

Created on 22 Oct 2020  路  4Comments  路  Source: salesforce/lwc

Description

This might be down at the compiler level.

When I attempt to load a module that exports a value as default, the compiler assumes it's a component and attempts to load the corresponding html file.

Steps to Reproduce

  1. create a resource that looks like this
// foo.js
function foo () {
  return "foo";
}

export default foo; 
  1. import it from another file
// bar.js
import foo from 'foo.js'
  1. The compiler will complain that foo.html doesn't exist.

Expected Results

I should be able to import foo without any errors.

Actual Results

 Error: Could not load /Users/gcordero/dist/lds/packages/@ldsjs/recipes/src/foo.html (imported by /Users/gcordero/dist/lds/packages/@ldsjs/recipes/src/foo.ts): ENOENT: no such file or directory, open '/Users/gcordero/dist/lds/packages/@ldsjs/recipes/src/foo.html'

Browsers Affected

N/A

Version

  • LWC: 1.8.16
BUG P2

Most helpful comment

@pmdartus Just realized this happens only when:

  • working with ts
  • using @rollup/plugin-typescript

There are a few other issues I've encountered when using @rollup/plugin-typescript + @lwc/rollup-plugin, we can file those on a different category if you'd like and we can close this.

Thanks for taking a look!

All 4 comments

FYI @kevinv11n @davidturissini

This issue has been linked to a new work item: W-8256543

I wasn't able to reproduce the same bug: https://codesandbox.io/s/import-html-bug-repro-rz7dj?file=/src/modules/x/bar/bar.js. Note that import foo from 'foo.js'; is treated as a bare module import and not a relative import. If you want to resolve foo.js you can import foo from './foo';

@gonzalocordero Could you share provide a full bug repro for us to investigate?

@pmdartus Just realized this happens only when:

  • working with ts
  • using @rollup/plugin-typescript

There are a few other issues I've encountered when using @rollup/plugin-typescript + @lwc/rollup-plugin, we can file those on a different category if you'd like and we can close this.

Thanks for taking a look!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

priandsf picture priandsf  路  5Comments

jodarove picture jodarove  路  5Comments

reiniergs picture reiniergs  路  5Comments

bmblb picture bmblb  路  3Comments

caridy picture caridy  路  3Comments