node.jses6-moduleslit-htmllit

Was able to resolve modules with Polymer 3, but not with Lit Element


I have always been able to use https://github.com/nodecg/express-transform-bare-module-specifiers with Polymer 3 and browser sync. But now I am getting errors with the set up and lit element

Uncaught TypeError: Failed to resolve module specifier "lit". Relative references must start with either "/", "./", or "../".

It is for the following files being requested:

/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js
/node_modules/lit/polyfill-support.js
/app/main-app.js
/node_modules/lit/polyfill-support.js.map

What has changed? A module is a module....this should work with lit element as it did with P3

Please do not recommend wds, while it is a great tool it does not fit my use case

My browser-sync config that works with Polymer 3 modules but not Lit:

const app = express();
const bs = require('browser-sync').create();
app.use('*', transformMiddleware());

bs.init({
  server: true,
  notify: false,
  "files": [

  ],
  middleware: [
    proxyMiddleware,
    historyApiFallback(),
  ],
  port: 4000,
  ui: false,
});


Solution

  • I realized I did not have app placed in the middleWare array.... Placing in app in the array fixed the issue and now browser sync works great with lit element and express-transform-bare-module-specifiers.

    const historyApiFallback = require('connect-history-api-fallback');
    const httpProxy = require('http-proxy');
    const path = require('path');
    const express = require('express');
    const transformMiddleware =
      require('express-transform-bare-module-specifiers').default;
    
    const app = express();
    const bs = require('browser-sync').create();
    
    app.use(transformMiddleware());
    
    bs.init({
      server: true,
      notify: false,
      "files": [
        'app/**/**/**/*',
        'app/**/**/*',
        'app/**/*',
        'app/*',
      ],
      middleware: [
        historyApiFallback(),
        app,
      ],
      port: 4000,
      ui: false,
    });