0

I want to host a web app on Google Firebase hosting, and import code from node modules, but I can't find the right way to go about this.

I have installed the modules on my dev machine into the main directory of the Firebase install, and imported them from my own JS file, but any way I try, I get error messages. For example (ol stands for OpenLayers):

import '../ol/ol.css';
import {Map, View} from '../ol';
import TileLayer from '../ol/layer/Tile';
import OSM from '../ol/source/OSM';

I then get these errors:

Failed to load module script: The server responded with a non-JavaScript MIME type of "text/css".

The MIME type in that error message is sometimes also "text/html".

Are there more steps than just placing package.json and node_modules in the right place?

I've tried tinkering around but am probably missing something obvious...

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
chris_l
  • 57
  • 6
  • It's not clear what you're trying to do here. Firebase Hosting just serves static content. It doesn't host a node app or run JavaScript code on the backend. You can write code for Cloud Functions and proxy Hosting to it, but that's a completely different thing than what you're doing here. – Doug Stevenson Oct 05 '19 at 15:16
  • Ok, I am using npm to install modules that I want to run in the Browser, I am using FB hosting to serve up the pages with these modules... – chris_l Oct 05 '19 at 17:35
  • 1
    The use of Firebase Hosting isn't really relevant here, since it just serves static code. It will work the same way that any hosting services delivers static content. It sounds like you're just having problems building that static content. – Doug Stevenson Oct 05 '19 at 18:39

1 Answers1

1

If that JS code is from a node file, you can't import a .css file there.

Check also Is it possible to import a .css file using ES6 modules?

Horatiu Jeflea
  • 7,256
  • 6
  • 38
  • 67