Running Grunt with node in windows fails

2019-08-20 11:27发布

问题:

Am trying to run a build on a Windows 10 machine that works fine on a Mac. Once I have cloned the repo and run npm run build then node app.js. The gruntfile.js is simple:

module.exports = function (grunt) {
    // Activate on subgrunt
    grunt.initConfig({
        run: {
            build: {
                cmd: 'npm',
                args: [
                    'run', 'build'
                ]
            }
        }
    });

    grunt.loadNpmTasks('grunt-run');

    grunt.registerTask('default', ['run']);
    grunt.registerTask('build', ['run']);
};

The node log with error shows this:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'watch' ]
2 info using npm@6.4.1
3 info using node@v8.12.0
4 verbose run-script [ 'prewatch', 'watch', 'postwatch' ]
5 info lifecycle media-attention-span@0.0.1~prewatch: media-attention-span@0.0.1
6 info lifecycle media-attention-span@0.0.1~watch: media-attention-span@0.0.1
7 verbose lifecycle media-attention-span@0.0.1~watch: unsafe-perm in lifecycle true
8 verbose lifecycle media-attention-span@0.0.1~watch: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\source\media-attention-span\node_modules\.bin;C:\apps\cmder\bin;C:\apps\cmder\vendor\conemu-maximus5\ConEmu\Scripts;C:\apps\cmder\vendor\conemu-maximus5;C:\apps\cmder\vendor\conemu-maximus5\ConEmu;C:\Program Files\Microsoft MPI\Bin\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\Common Files\Microsoft Shared\Microsoft Online Services;C:\Program Files (x86)\Common Files\Microsoft Shared\Microsoft Online Services;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program Files\PuTTY\;C:\Program Files\Git\cmd;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\nodejs\;C:\Users\Mark\AppData\Local\Microsoft\WindowsApps;C:\Users\Mark\AppData\Roaming\npm;C:\Program Files\Git\mingw64;C:\Program Files\Git\usr\bin;C:\apps\cmder
9 verbose lifecycle media-attention-span@0.0.1~watch: CWD: C:\source\media-attention-span
10 silly lifecycle media-attention-span@0.0.1~watch: Args: [ '/d /s /c',
10 silly lifecycle   'watch \'npm run build\' static/js static/style views' ]
11 silly lifecycle media-attention-span@0.0.1~watch: Returned: code: 1  signal: null
12 info lifecycle media-attention-span@0.0.1~watch: Failed to exec watch script
13 verbose stack Error: media-attention-span@0.0.1 watch: `watch 'npm run build' static/js static/style views`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:915:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid media-attention-span@0.0.1
15 verbose cwd C:\source\media-attention-span
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "watch"
18 verbose node v8.12.0
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error media-attention-span@0.0.1 watch: `watch 'npm run build' static/js static/style views`
22 error Exit status 1
23 error Failed at the media-attention-span@0.0.1 watch script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

There is also an app.js file that seems to be called and it looks like:

const express = require('express');
const app = express();

const api = require('./src/nyt-api');
const router = require('./src/customApi.js');

app.use('/static', express.static(__dirname + '/static'));

app.get('/', (req, res) => res.sendFile(__dirname + '/views/index.html'));
app.get('/timeline', (req, res) => res.sendFile(__dirname + '/views/timeline.html'))
app.get('/data', (req, res) => {
    api.entityData(entities => {
        res.status(200).json({ data: entities });
    });
});

app.get('/static/data/dma-topo.json', (req, res) => {
  res.sendFile(path.join(__dirname, '/static/data', 'dma-topo.json'));
});

app.get('/static/data/dma-topology.json', (req, res) => {
  res.sendFile(path.join(__dirname, '/static/data', 'dma-topopology.json'));
});

app.use('/', router);

app.listen(3000, () => console.log('Listening on port 3000'));

From reading other posts, thought maybe something to do with single quotes versus double in windows or some sort of weird permissions issue?

Seems to me, it has something to do with the way pathing is in Mac versus Windows and the way this is setup. Any suggestions or fixes for this?