Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
Unable to require tag on server side in Riot JS

When I declare: require('./public_html/Tags/blog_post_details.tag'), I get the following error:

E:\WORKSPACE\NETBEANS_WORKSPACE\MyProject\public_html\Tags\blog_post_details.tag:1
(function (exports, require, module, __filename, __dirname) { <blog_post_details >
                                                              ^

SyntaxError: Unexpected token <
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (E:\WORKSPACE\NETBEANS_WORKSPACE\MyProject\server.js:7:1)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)

The path is correct because this line works var commonsFile = require('./public_html/Tags/commons.json');

WebPack config file:

var path = require('path');
var webpack = require('webpack');
module.exports = {
    entry: './index.js',
    output: {
        path: __dirname,
        filename: 'public_html/assets/js/bundle.js'
    },
    resolveLoader: {
        root: path.join(__dirname, 'node_modules')
    },

    module: {
        preLoaders: [{
            test: /\.tag$/,
            exclude: /node_modules/,
            loader: 'riotjs-loader',
            query: {
                //type: 'none'
                //compact: true
            }
        }],
        loaders: [
            /*{
                test: /\.tag$/,
                loader: 'tag',
                exclude: /node_modules/
            },*/
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                query: {
                    //commenting because of this issue https://github.com/mapbox/mapbox-gl-js/issues/3422
                   // presets: ['es2015']
                }
            }
        ]
    },
    plugins: [
        new webpack.optimize.OccurenceOrderPlugin(),
        new webpack.ProvidePlugin({
            riot: 'riot'
        })
    ]
};
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The node require function only recognizes files ending in .js for Javascript files, .json for JSON files, and .node for binary extensions to the Node runtime. In the case of Javascript files, you can omit the trailing .js if the file or module can be found by Node's module system (i.e. under node_modules).

From your example, it appears that you are attempting to use require from client-side code. Unless you use browserify, webpack or another client-side bundler which provide their own client-side version of require, you cannot use it.

As noted in my comment below, the video link you provide shows client-side code loading tag files via webpack. You'll need to check webpack's config to assure it is properly bundling your tag files for delivery to the browser. Again from the video, the example code is loading its tag file from ./tags/filename.tag where the root of that path is defined by webpack.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda