Npm returns Invalid Token when building in TeamCity

I have a React application that I am trying to build within TeamCity.

On my local machine, I can run "npm install", and "npm run build", and everything compiles just fine.

On the TeamCity server, I can do the same thing and everything runs just fine.

However, when the TeamCity service runs the same commands in the work directory, it gets an unusual error, "Module parse failed: C:\TeamCity\buildAgent\work\2f0ae86b255ab924\dev\app\app.js Unexpected token (47:2)"

The odd thing is, when I copy the working directory (2f0ae86b255ab924) to another directory on the build server, for example the C:\Temp directory, and I run "npm run build" manually, everything runs fine.  But if I run it in the "C:\TeamCity\buildAgent\work\2f0ae86b255ab924" directory, I get the error above.  I can replicate this by running the command manually in a command prompt, or by running it in the Build Agent.

 

The issue appears to happen whenever the build occurs under the "C:\TeamCity\BuildAgent" directory.  If the folder is located somewhere else, then everything is just fine.

 

For kicks and giggles, I created a copy of the directory called "C:\TeamCity\builtAgent\work\2f0ae86b255ab924", and ran "npm run build", and everything built just fine.  I then renamed the folder to "C:\TeamCity\buildAgent\work\2f0ae86b255ab924", ran it again, and everything failed again.

 

 

Here is the build log:

[14:45:23][Step 2/3] Starting: C:\TeamCity\buildAgent\temp\agentTmp\custom_script1343798775008708046.cmd
[14:45:23][Step 2/3] in directory: C:\TeamCity\buildAgent\work\2f0ae86b255ab924
[14:45:25][Step 2/3]
[14:45:25][Step 2/3] > ridesystems-admin@0.0.1 build C:\TeamCity\buildAgent\work\2f0ae86b255ab924
[14:45:25][Step 2/3] > npm run clean-build && npm run copy && npm run build:scripts && npm run reversion
[14:45:25][Step 2/3]
[14:45:27][Step 2/3]
[14:45:27][Step 2/3] > ridesystems-admin@0.0.1 clean-build C:\TeamCity\buildAgent\work\2f0ae86b255ab924
[14:45:27][Step 2/3] > rimraf build
[14:45:27][Step 2/3]
[14:45:29][Step 2/3]
[14:45:29][Step 2/3] > ridesystems-admin@0.0.1 copy C:\TeamCity\buildAgent\work\2f0ae86b255ab924
[14:45:29][Step 2/3] > npm run copy:dist
[14:45:29][Step 2/3]
[14:45:30][Step 2/3]
[14:45:30][Step 2/3] > ridesystems-admin@0.0.1 copy:dist C:\TeamCity\buildAgent\work\2f0ae86b255ab924
[14:45:30][Step 2/3] > cpx "./dev/assets/images/**/*.{png,gif,jpg,ico,svg}" ./build/assets/images && cpx "./dev/**/*.{html,ico}" ./build/
[14:45:30][Step 2/3]
[14:45:33][Step 2/3]
[14:45:33][Step 2/3] > ridesystems-admin@0.0.1 build:scripts C:\TeamCity\buildAgent\work\2f0ae86b255ab924
[14:45:33][Step 2/3] > npm run pack-js
[14:45:33][Step 2/3]
[14:45:35][Step 2/3]
[14:45:35][Step 2/3] > ridesystems-admin@0.0.1 pack-js C:\TeamCity\buildAgent\work\2f0ae86b255ab924
[14:45:35][Step 2/3] > webpack --config ./webpack.prod.config.js
[14:45:35][Step 2/3]
[14:45:38][Step 2/3] Hash: 3901a9cbe36d24090134
[14:45:38][Step 2/3] Version: webpack 1.13.3
[14:45:38][Step 2/3] Time: 2446ms
[14:45:38][Step 2/3] Asset Size Chunks Chunk Names
[14:45:38][Step 2/3] scripts.js 86.3 kB 0 [emitted] main
[14:45:38][Step 2/3] [0] multi main 40 bytes {0} [built] [1 error]
[14:45:38][Step 2/3] [298] ./dev/app/app.js 0 bytes [built] [failed]
[14:45:38][Step 2/3] + 297 hidden modules
[14:45:38][Step 2/3]
[14:45:38][Step 2/3] ERROR in ./dev/app/app.js
[14:45:38][Step 2/3] Module parse failed: C:\TeamCity\buildAgent\work\2f0ae86b255ab924\dev\app\app.js Unexpected token (47:2)
[14:45:38][Step 2/3] You may need an appropriate loader to handle this file type.
[14:45:38][Step 2/3] SyntaxError: Unexpected token (47:2)
[14:45:38][Step 2/3] at Parser.pp$4.raise (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:2221:15)
[14:45:38][Step 2/3] at Parser.pp.unexpected (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:603:10)
[14:45:38][Step 2/3] at Parser.pp$3.parseExprAtom (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:1822:12)
[14:45:38][Step 2/3] at Parser.pp$3.parseExprSubscripts (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:1715:21)
[14:45:38][Step 2/3] at Parser.pp$3.parseMaybeUnary (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:1692:19)
[14:45:38][Step 2/3] at Parser.pp$3.parseExprOps (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:1637:21)
[14:45:38][Step 2/3] at Parser.pp$3.parseMaybeConditional (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:1620:21)
[14:45:38][Step 2/3] at Parser.pp$3.parseMaybeAssign (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:1597:21)
[14:45:38][Step 2/3] at Parser.pp$3.parseExprList (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:2165:22)
[14:45:38][Step 2/3] at Parser.pp$3.parseSubscripts (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:1741:35)
[14:45:38][Step 2/3] at Parser.pp$3.parseExprSubscripts (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:1718:17)
[14:45:38][Step 2/3] at Parser.pp$3.parseMaybeUnary (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:1692:19)
[14:45:38][Step 2/3] at Parser.pp$3.parseExprOps (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:1637:21)
[14:45:38][Step 2/3] at Parser.pp$3.parseMaybeConditional (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:1620:21)
[14:45:38][Step 2/3] at Parser.pp$3.parseMaybeAssign (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:1597:21)
[14:45:38][Step 2/3] at Parser.pp$3.parseExpression (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:1573:21)
[14:45:38][Step 2/3] at Parser.pp$1.parseStatement (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:727:47)
[14:45:38][Step 2/3] at Parser.pp$1.parseTopLevel (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:638:25)
[14:45:38][Step 2/3] at Parser.parse (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:516:17)
[14:45:38][Step 2/3] at Object.parse (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\node_modules\acorn\dist\acorn.js:3098:39)
[14:45:38][Step 2/3] at Parser.parse (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\lib\Parser.js:902:15)
[14:45:38][Step 2/3] at DependenciesBlock.<anonymous> (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack\lib\NormalModule.js:104:16)
[14:45:38][Step 2/3] at DependenciesBlock.onModuleBuild (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack-core\lib\NormalModuleMixin.js:310:10)
[14:45:38][Step 2/3] at nextLoader (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack-core\lib\NormalModuleMixin.js:275:25)
[14:45:38][Step 2/3] at C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\webpack-core\lib\NormalModuleMixin.js:259:5
[14:45:38][Step 2/3] at Storage.finished (C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:38:16)
[14:45:38][Step 2/3] at C:\TeamCity\buildAgent\work\2f0ae86b255ab924\node_modules\graceful-fs\graceful-fs.js:78:16
[14:45:38][Step 2/3] at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:445:3)
[14:45:38][Step 2/3] @ multi main
[14:45:40][Step 2/3]
[14:45:40][Step 2/3] > ridesystems-admin@0.0.1 reversion C:\TeamCity\buildAgent\work\2f0ae86b255ab924
[14:45:40][Step 2/3] > node ./bin/reversion
[14:45:40][Step 2/3]
[14:45:40][Step 2/3]
[14:45:40][Step 2/3] Error!
[14:45:40][Step 2/3]
[14:45:40][Step 2/3] We cannot find all these files, are you sure the paths are correct for every one?
[14:45:40][Step 2/3] build/assets/main.css
[14:45:40][Step 2/3] build/assets/scripts.js
[14:45:40][Step 2/3] build/index.html
[14:45:40][Step 2/3]
[14:45:40][Step 2/3] Remember paths are relative to where you are running the script.
[14:45:40][Step 2/3]
[14:45:40][Step 2/3]
[14:45:40][Step 2/3] err
[14:45:40][Step 2/3] We cannot find all these files, are you sure the paths are correct for every one?
[14:45:40][Step 2/3] build/assets/main.css
[14:45:40][Step 2/3] build/assets/scripts.js
[14:45:40][Step 2/3] build/index.html
[14:45:40][Step 2/3]
[14:45:40][Step 2/3] Remember paths are relative to where you are running the script.
[14:45:40][Step 2/3]
[14:45:40][Step 2/3]
[14:45:40][Step 2/3] Process exited with code 0
0
1 comment

Hello,

Sorry for delay. Is the issue still actual? It's rather strange that the folder renaming helps to fix the issue. Did you run all tests under the same user? Perhaps if you create directory manually it has different permissions assigned then directory created by TeamCity. Please check it.

0

Please sign in to leave a comment.