Falscher MIME -Typ mit benutzerdefinierten nächsten.js -ServerCSS

CSS verstehen
Guest
 Falscher MIME -Typ mit benutzerdefinierten nächsten.js -Server

Post by Guest »

Ich schreibe eine Next.js -App mit einer benutzerdefinierten Server.js -Datei und ich kann mein CSS nicht laden - ich erhalte immer wieder Folgendes in der Browserkonsole:

Code: Select all

The resource from “http://localhost:3000/_next/
static/development/pages/index.js?ts=1552499710032”
was blocked due to MIME type (“text/html”)
mismatch (X-Content-Type-Options: nosniff)
< /code>
Und ich weiß nicht warum. Soweit ich das beurteilen kann, habe ich meine App so konfiguriert, wie ich es für eine frühere Arbeitsversion getan habe. Hier ist meine nächste.config.js 
Datei:

Code: Select all

const withCSS = require('@zeit/next-css');
const withImages = require('next-images');
const path = require('path')
const Dotenv = require('dotenv-webpack')
require('dotenv').config()

module.exports =  withImages(withCSS({
webpack: config => {
// Fixes npm packages that depend on `fs` module
config.node = {
fs: 'empty'
}

config.plugins = config.plugins || []

config.plugins = [
...config.plugins,

// Read the .env file
new Dotenv({
path: path.join(__dirname, '.env'),
systemvars: true
})
]

return config
}
}))
Und hier ist mein server.js Datei:

Code: Select all

const express = require('express')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

const path = require('path');
const options = {
root: path.join(__dirname, '/static'),
headers: {
'Content-Type': 'text/plain;charset=UTF-8',
}
};

app.prepare().then(() => {
const server = express()

server.get('/robots.txt', (req, res) => {
return res.status(200).sendFile('robots.txt', options)
});

server.get('/sitemap.xml', (req,res) => {
return res.status(200).sendFile('sitemap.xml', options)
});

server.get('/', (req, res) => {
return app.render(req, res, '/', req.query)
})

server.listen(port, err => {
if (err) throw err
console.log(`> Ready on http://localhost:${port}`)
})
})
Ich führe meine App mit node server.js aus und importiere das CSS mithilfe von Imports "./styles/root.css" (mein einziger und nur CSS -Datei) also keine Überraschungen dort. Was läuft schief? Ich habe hier einen Bericht eröffnet: https://github.com/zeit/next.js/issues/6647.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post